How to find files in the entire disk hard disk using MFC?

Use MFC to develop, you can use the CFileFind class to search for files. MFC completely encapsulates the function of file search. The member functions used for file search are:

virtual BOOL FindFile( LPCTSTR pstrName = NULL, DWORD dwUnused = 0 ); Start to query 
virtual BOOL FindNextFile( ); Find files, for the first file and the next file, use this function to query 
// Below is a piece of file search demo code 
   CFileFind finder; 
   strWildcard += _T("//*.*"); 
   BOOL bWorking = finder.FindFile(strWildcard); 
   while (bWorking) 
   { 
      bWorking = finder.FindNextFile(); 
      //Your own processing code 
   } 
   finder. Close(); 

At the same time, a lot of judgment functions are encapsulated in CFileFind to determine various attributes of the file. These functions are 
GetLength to obtain the file length, 
GetFileName to obtain the file name, 
GetFilePath to obtain the file path name and file name, 
GetCreationTime / GetLastAccessTime / GetLastWriteTime to obtain the file time 
IsDots judgment Whether the file is... or... 
IsReadOnly / IsDirectory / IsCompressed / IsSystem / IsHidden / IsTemporary / IsNormal /IsArchived get file attributes

//The following is a directory traversal function implemented with the CFileFind class in MFC 
// The calling method is MFC_Dir_A_S("c://") 
void MFC_Dir_A_S(LPCSTR pszDir) 
{ 
	printf("%s/n",pszDir); 
	CFileFind ff ; 
	char szDirFile[1024]; 
	sprintf(szDirFile,"%s*",pszDir); 
	if (ff.FindFile(szDirFile)) 
	{ 
		char szDir[1024]; 
		while(ff.FindNextFile()) 
		{ 
			if(ff.IsDirectory () &&! ff.IsDots()) 
			{//Make sure to find a directory and it is not. or.. 
				sprintf(szDir,"%s%s//",pszDir,ff.GetFileName()); 
				//printf( "%s/n",szDir); 
				MFC_Dir_A_S(szDir);
			}
		}
		ff.Close();//Close 
	} 
}

https://www.cnblogs.com/txwtech/p/13159438.html

Guess you like

Origin blog.csdn.net/txwtech/article/details/106842353