This article describes a method for traversing a file under a folder in C + +. Share to everyone for your reference. as follows:
#include <windows.h> #include <stdio.h> #include <string.h> #define LEN 1024
Depth precedence recursively traverses all files in the directory BOOL directorylist (lpcstr Path) {win32_find_data FindData;
HANDLE Herror;
int filecount = 0;
Char Filepathname[len];
Construct path Char Fullpathname[len];
strcpy (Filepathname, Path);
strcat (Filepathname, "\\*.*");
Herror = FindFirstFile (Filepathname, &finddata);
if (Herror = = Invalid_handle_value) {printf ("Search failed!");
return 0;
while (:: FindNextFile (Herror, &finddata)) {//worry. and.
if (strcmp (Finddata.cfilename, ".") = = 0 | | strcmp (finddata.cfilename, "...") = = 0) {continue;
}//Construct full path wsprintf (fullpathname, "%s\\%s", path,finddata.cfilename);
filecount++;
Output this level of the file printf ("\n%d%s", FileCount, Fullpathname);
if (Finddata.dwfileattributes & file_attribute_directory) {printf ("<Dir>");
Directorylist (Fullpathname);
} return 0;
} void Main () {directorylist ("D:eclipse-j2ee");}
I hope this article will help you with your C + + programming.