"123"I baidu, is to find the a directory traversal, I want to realize the D disc lookup
There are big?
CodePudding user response:
Recursive calls, reference
Void the find (LPCTSTR lpPath vector& FileList)
{
String szFind (lpPath);
WIN32_FIND_DATA FindFileData;
SzFind +=_T (" \ \ *. * ");
HANDLE hFind=: : FindFirstFile (szFind c_str (), & amp; FindFileData);
If (INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/=hFind) return;
//
Do
{
If (FindFileData dwFileAttributes & amp; FILE_ATTRIBUTE_DIRECTORY)
{//dir
If (FindFileData cFileName [0]! )
='. '{
String szPath (lpPath);
SzPath +=_T (" \ \ ");
SzPath +=FindFileData. CFileName;
//TRACE1 (" % s \ n ", szPath c_str ());
Find (szPath. C_str (), the FileList);
}
}
The else
{//file
String strFileName=FindFileData. CFileName;//file name
//TRACE1 (" % s \ n ", strFileName c_str ());
Int the at=strFileName. Find_last_of (');
If (at<0) continue;//file without extention
String ext.=strFileName substr (at);
//TRACE1 (" % s \ n ", ext c_str ());
//
The at=0;//reset
While (((int) at=suffixStr. Find (ext, ats)) & gt;=0)//find the type
//if (stricmp (suffixStr c_str (), _T (". TXT "))==0)
{//not suffixStr. C_str ()==_T (". TXT "); Never==!
//afxDump & lt;The at +=ext size ();//move to seperetor '
If (suffixStr [at]!='.') continue;//not wanted!
//
FILETIME ft=FindFileData. FtCreationTime;
SYSTEMTIME st={0};
TCHAR buf [64]={0};
FileTimeToLocalFileTime (& amp; (FindFileData. FtCreationTime), & amp; Ft);
FileTimeToSystemTime (& amp; The ft, & amp; St);
Sprintf (buf, _T (" % % 4 d years 02 02 on 02 d % d % d: % 02 d: % 2 d "),
St. wYear, st. wMonth, st. wDay, st. wHour/* */Beijing time, st. wMinute, st. wSecond);
String strFilePath=lpPath;
The FileInfo fi;
Fi. SzFileName=strFileName;
Fi. SzFilePath=strFilePath;
Fi. SzCreateTime=buf;
//TRACE1 (" % s \ n ", strFileName c_str ());
FileList. Push_back (fi);
}
}
} while (: : FindNextFile (hFind, & amp; FindFileData));
}
CodePudding user response: