I remember reading programs written by someone else using MFC to traverse the folder list. Using the GetNextPathName () function in the CFileDialog class, I can easily traverse time files.
However, MFC is too old to call and requires dynamic links.
The Directory class and File class of CLR do not feel familiar with themselves. They always feel that they are finished and there is no possibility of porting.
So I recently used Windows functions to write a traversal folder, forming chained information about its internal members in the memory, and printing the members in the memory into a text file.
Considering that the file path is getting longer and longer, and the characters are complicated. Therefore, all internal processing uses the UTF16 dynamic array Wstring, which has a limit on the path length. There should be a problem with the Chinese directory. (I think this program certainly does not support files named in some small languages ...... After all, there are too few 65536 characters in a 16-bit representation. No wonder the Chinese Simplified and traditional code pages are 932 and 950 respectively)
The program Link is here and there are no points. You are welcome to use the discussion.
Http://download.csdn.net/detail/sera_ph/4625402
The program is compiled through vs2008. You only need to add the windows. h library function and define UNICODE.
The main function of the program is simplified as follows:
[Cpp]
Int _ tmain (int argc, _ TCHAR * argv [])
{
// Obtain the path of the folder with internal information from the Parameter
Std: wstring original_path (L "c: \ windows ");
// Store files in queue format
Std: list <class theFile *> l_pfile;
// Generate a file queue
Int result = generateList (original_path, & l_pfile );
// If the monitoring result =-1, the access to this directory is incorrect.
// Print the file queue
Print_list ("d: \ filelog.txt", & l_pfile );
// Release the queue in the memory
Return 0;
}
The files and information in the directory are stored in the form of a custom class theFile pointer. The pointer queue of the members in the folder is l_pfile.
I just typed it on CSDN. Silently.
In the file generation queue, the windows function used is:
HListFile = FindFirstFile (LPCWSTR) szFullPath_a, & FindFileData );
FindNextFile (hListFile, & FindFileData)
Two WIN32_FIND_DATA FindFileData; HANDLE hListFile; are the query HANDLE and result.
The file information is visible in the WIN32_FIND_DATA FindFileData member. Generally, the modification time and attributes are shown in the figure below:
The execution efficiency should be slightly higher than that of mfc. After all, it is more underlying. For more than 80 thousand file traversal in the windows directory, it takes less than 3 seconds for my laptop to establish a queue, write files, and release memory.