Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<windows.h>
- int main(int argc, char** argv);
- void dirListFiles(const char* startDir);
- int main(int argc, char** argv)
- {
- const char* startDir = "C:\\Users\\Filip\\Desktop\\root";
- dirListFiles(startDir);
- system("pause");
- return 0;
- }
- void dirListFiles(const char* startDir)
- {
- HANDLE hFind;
- WIN32_FIND_DATA wfd;
- char path[MAX_PATH];
- sprintf(path, "%s\\*", startDir);
- fprintf(stdout, "In Directory \"%s\"\n\n", startDir);
- if ((hFind = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "FindFirstFile failed on path = \"%s\"\n", path);
- abort();
- }
- BOOL cont = TRUE;
- while (cont == TRUE)
- {
- if ((strncmp(".", wfd.cFileName, 1) != 0) && (strncmp("..", wfd.cFileName, 2) != 0))
- {
- if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- {
- sprintf(path, "%s\\%s", startDir, wfd.cFileName);
- dirListFiles(path);
- }
- else
- {
- //do your work here -- mildly klugy comparison
- fprintf(stdout, "File \"%s\\%s\"\n\n", startDir, wfd.cFileName);
- }
- }
- cont = FindNextFile(hFind, &wfd);
- }
- if (GetLastError() != ERROR_NO_MORE_FILES)
- {
- fprintf(stderr, "FindNextFile died for some reason; path = \"%s\"\n", path);
- abort();
- }
- if (FindClose(hFind) == FALSE)
- {
- fprintf(stderr, "FindClose failed\n");
- abort();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement