请问,有什么函数或者控件可以逐一读出一个目录下的所有文件名?谢谢!

解决方案 »

  1.   

    CFileFind,你可以去查查帮助就会用了
      

  2.   

    #include <afx.h>
    #include <iostream>using namespace std;void Recurse(LPCTSTR pstr)
    {
       CFileFind finder;   // build a string with wildcards
       CString strWildcard(pstr);
       strWildcard += _T("\\*.*");   // start working for files
       BOOL bWorking = finder.FindFile(strWildcard);   while (bWorking)
       {
          bWorking = finder.FindNextFile();      // skip . and .. files; otherwise, we'd
          // recur infinitely!      if (finder.IsDots())
             continue;      // if it's a directory, recursively search it      if (finder.IsDirectory())
          {
             CString str = finder.GetFilePath();
             cout << (LPCTSTR) str << endl;
             Recurse(str);
          }
       }   finder.Close();
    }void main()
    {
       if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0)
          cout << "panic!" << endl;
       else
          Recurse(_T("C:"));
    }
      

  3.   

    BROWSEINFO bi;  
        char dispname[MAX_PATH], path[MAX_PATH], searchfolder[MAX_PATH], title[MAX_PATH], createtime[30];  
        ITEMIDLIST * pidl;
    CString filetitle;
    BOOL bRet;
    FILETIME * time;
    SYSTEMTIME * systime; time = new FILETIME;
    systime = new SYSTEMTIME;
    memset(dispname, 0, MAX_PATH);
    memset(path, 0, MAX_PATH);
    memset(searchfolder, 0, MAX_PATH);
    memset(title, 0, MAX_PATH);
    memset(createtime, 0, 30);    bi.hwndOwner = 0;  
        bi.pidlRoot = 0;  
        bi.pszDisplayName = dispname;  
        bi.lpszTitle = "选择文件夹";  
        bi.ulFlags = BIF_RETURNONLYFSDIRS;  
        bi.lpfn = 0;
        bi.lParam = 0;  
        bi.iImage = 0;  
        
        if (pidl = SHBrowseForFolder(&bi)) //弹出文件夹浏览窗口,并选取目录
        {
    DelList();        SHGetPathFromIDList(pidl, path);  
            GetDlgItem(IDC_BROWSE)->SetWindowText(path);
    sprintf(searchfolder, "%s\\*.*", path); bRet = filefind.FindFile(searchfolder, 0);

    if (bRet)
    {
    bRet = filefind.FindNextFile();
    while(bRet)
    {
    filetitle = filefind.GetFileTitle();
    sprintf(title, "%s", filetitle);
    bRet = filefind.GetCreationTime(time);
    FileTimeToSystemTime(time, systime);
    sprintf(createtime, "%d-%d-%d %d:%d:%d",
    systime->wYear,
    systime->wMonth,
    systime->wDay,
    systime->wHour,
    systime->wMinute,
    systime->wSecond);
    if (filefind.IsDirectory())
    {
    InsertList(1, title, createtime);
    }
    else
    {
    InsertList(0, title, createtime);
    }
    bRet = filefind.FindNextFile();
    }
    filetitle = filefind.GetFileTitle();
    sprintf(title, "%s", filetitle);
    bRet = filefind.GetCreationTime(time);
    FileTimeToSystemTime(time, systime);
    sprintf(createtime, "%d-%d-%d %d:%d:%d",
    systime->wYear,
    systime->wMonth,
    systime->wDay,
    systime->wHour,
    systime->wMinute,
    systime->wSecond);
    if (filefind.IsDirectory())
    {
    InsertList(1, title, createtime);
    }
    else
    {
    InsertList(0, title, createtime);
    }
    }
        }