Traverse Win32 folder

zhaozj2021-02-16  47

Folder traversal technology is a very useful technology that uses this technology in the file search and anti-virus software. I will discuss how to implement this technology in Win32. The core of folder traversal technology is to use the recursive algorithm. I will not introduce the recursive algorithm. If you don't understand, please refer to the relevant content. The following is my algorithm pseudo code: void function (LPCTSTR LPSZPATH) {start looking for; if (no file found) return; do {if (found by the file) Function (found directory); ELSE While (looking for the next file and success);} The API function and the structure that implementing this algorithm and the structure are: · FindFirstFile; · FindNextFile; · Win32_find_data. Here I assume that you have understood the above functions and structures, now let's begin. Now I will write the code that starts looking for. Prior to this, I first assume that the function parameter LPSZPath passed into the path format is X: / (root directory) or x: / div (non-root), because the Win32 programming is usually used in this path format. You must notice that if the path is the root directory, there is a path separator "/" behind it, no. Then I have to handle these two situations when I write code. This code is as follows: tchar szfind [max_path]; lstrcpy (szfind, lpszpath); if (! Isroot (szfind)) // isroot is a function I have written in my own, and if the parameter is the root directory, return TruelStrcat (Szfind, "/ / "); LSTRCAT (SZFIND," ​​*. * "); // find all files WIN32_FIND_DATA WFD; Handle Hfind = FindFirstFile (Szfind, & WFD); if (HFIND == Invalid_Handle_Value) // If you do not find or find failed Return; Below I will discuss what if I find a file, what should I do. However, before this, please enter the MS-DOS method, and enter DIR Enter, what did you see?

转载请注明原文地址:https://www.9cbs.com/read-22539.html

New Post(0)