Home > Software engineering >  C/MFC realize find D dish all file names containing "123" file
C/MFC realize find D dish all file names containing "123" file

Time:09-15

VS2010/c + + MFC realize find D dish all file names contain file
"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:

refer to the original poster duo lai mi duo duo response:
VS2010/c + + MFC realize find D dish all file names contain file
"123"I baidu, is traversal search a directory under , I want to achieve the D disc find
Are there any big

the D disc is a directory

CodePudding user response:

D: \ \ is a directory

CodePudding user response:

D: \ \ is a directory

CodePudding user response:

Recursion can fix the problem

CodePudding user response:

CFileFind: : FindFile/FileNextFile (); Enumeration file

CodePudding user response:

Find file, if the folder is the recursive search, if is to operate file determine the filename
 
Void ShowFile (cstrings str_Dir, HTREEITEM tree_Root)
{
CFileFind FileFind;
HTREEITEM tree_Temp;
(1) if (str_Dir. Right!
="\ ")Str_Dir +="\ ";
Str_Dir +="*. *";
BOOL res=FileFind. FindFile (str_Dir);
While (res)
{
Tree_Temp=tree_Root;
Res=FileFind. FindNextFileW ();
If (FileFind IsDirectory () & amp; & ! FileFind. IsDots ())
{
Cstrings strPath=FileFind. GetFilePath ();
Cstrings strTitle=FileFind. GetFileName ();
Tree_Temp=m_tree_local. InsertItem (strTitle, 0, 0, tree_Root);//, TVI_LAST
ShowFile (strPath, tree_Temp);
}
else if (! FileFind. IsDirectory () & amp; & ! FileFind. IsDots ())
{
.//cstrings strPath=FileFind GetFilePath ();//get the path, as the beginning of the recursive call
.//cstrings strTitle=FileFind GetFileName ();//get the file name, as a node of the tree control
//m_tree_local InsertItem (strTitle, 2, 2, tree_Temp);//m_tree_Project
}
}
FileFind. Close ();
}

CodePudding user response:

D dish is also a folder,

CodePudding user response:

Using CFileFind object,

CFileFind finder.
BOOL bWorking=finder. FindFile (" * 123 *. * ");
While (bWorking)
{
BWorking=finder. The FindNextFile ();
Cout & lt; <(LPCTSTR) finder. GetFileName () & lt; }
  • Related