The following code will enumerate all the files in the current directory, printing the name of each file:CFileFind finder; BOOL bWorking = finder.FindFile("*.*"); while (bWorking) { bWorking = finder.FindNextFile(); cout << (LPCTSTR) finder.GetFileName() << endl; }
FindFirstFile("*.*", &wfd); 注意要排除.和..两个目录
void FindFileMy(CString strPath) { CFileFind finder; CTime tmcreate; int ncol; CString strTime; // build a string with wildcards CString strWildcard(strPath); strWildcard += _T("\\*.txt"); // 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()) { //file //CString str2 = finder.GetFilePath(); CString str2 = finder.GetFileName(); //找到文件了,是文件。 你可以进行处理, } else { //directory CString str3 = finder.GetFilePath(); //FindFileMy(str3); //不用在更下一级别中去查找文件夹,如果想在下一级别中查找,请要这句 } } finder.Close(); }
WIN32_FIND_DATA file_info;
char file_name[1024] = "";
HANDLE handle;
char *route = (char*)malloc(strlen(dirName) + 5);
char *pathname // 查找目录,
sprintf(route, "%s\\*.*", pathname);
handle = FindFirstFile(route, &file_info);
free(route);
if(INVALID_HANDLE_VALUE != handle)
{ //
do{
char *tempname = (char *)malloc(260);
sprintf(tempname, file_info.cFileName); //文件名字
//处理该文件
tempname = NULL;
}while( FindNextFile(handle, &file_info) );这样你就可以找到所有包含在目录路经下的文件,在去匹配看是不是你指定的文件就可以了。
BOOL bWorking = finder.FindFile("*.*");
while (bWorking)
{
bWorking = finder.FindNextFile();
cout << (LPCTSTR) finder.GetFileName() << endl;
}
注意要排除.和..两个目录
{
CFileFind finder;
CTime tmcreate;
int ncol;
CString strTime;
// build a string with wildcards
CString strWildcard(strPath);
strWildcard += _T("\\*.txt"); // 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())
{ //file
//CString str2 = finder.GetFilePath();
CString str2 = finder.GetFileName(); //找到文件了,是文件。 你可以进行处理, }
else
{ //directory
CString str3 = finder.GetFilePath();
//FindFileMy(str3); //不用在更下一级别中去查找文件夹,如果想在下一级别中查找,请要这句 }
} finder.Close();
}