请问,有什么函数或者控件可以逐一读出一个目录下的所有文件名?谢谢!
解决方案 »
- TCP怎样实现客户端客户端之间的连接!
- 过度讲解的教材不是一本好教材——看《深入浅出MFC》有感
- mfc的工程可以一直循环执行吗?socket要怎么循环收包?
- 重设 CListCtrl 列文本
- ATL中有没有CinternetConnection这样的HTTP封装的类?
- ATL项目中普通类通过CoCreateInstance获取IXMLDOMDocument接口时返回E_NOINTERFACE
- 高手请进:帮我解决recvfrom的问题?(如果接收的数据不定长,那怎么设置接受的长度呢)
- 关于从主机字节顺序转换到网络字节顺序的问题
- 郁闷!!给点帮助或提点建议,谢谢。
- 如何看别人的源代码???
- listbox的问题
- 为什么的我的程序在屏保退出后也自己退出了.急!!!!!!!
#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:"));
}
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);
}
}
}