Advertisement
filip710

windows obilazak

Apr 10th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3.  
  4. #include<stdio.h>
  5. #include<windows.h>
  6.  
  7. int main(int argc, char** argv);
  8. void dirListFiles(const char* startDir);
  9.  
  10.  
  11. int main(int argc, char** argv)
  12. {
  13.     const char* startDir = "C:\\Users\\Filip\\Desktop\\root";
  14.  
  15.     dirListFiles(startDir);
  16.  
  17.     system("pause");
  18.     return 0;
  19. }
  20.  
  21. void dirListFiles(const char* startDir)
  22. {
  23.     HANDLE hFind;
  24.     WIN32_FIND_DATA wfd;
  25.     char path[MAX_PATH];
  26.  
  27.     sprintf(path, "%s\\*", startDir);
  28.  
  29.  
  30.  
  31.     fprintf(stdout, "In Directory \"%s\"\n\n", startDir);
  32.  
  33.     if ((hFind = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
  34.     {
  35.         fprintf(stderr, "FindFirstFile failed on path = \"%s\"\n", path);
  36.         abort();
  37.     }
  38.  
  39.     BOOL cont = TRUE;
  40.     while (cont == TRUE)
  41.     {
  42.         if ((strncmp(".", wfd.cFileName, 1) != 0) && (strncmp("..", wfd.cFileName, 2) != 0))
  43.         {
  44.             if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  45.             {
  46.                 sprintf(path, "%s\\%s", startDir, wfd.cFileName);
  47.                 dirListFiles(path);
  48.             }
  49.             else
  50.             {
  51.                 //do your work here -- mildly klugy comparison
  52.                 fprintf(stdout, "File \"%s\\%s\"\n\n", startDir, wfd.cFileName);
  53.  
  54.             }
  55.         }
  56.         cont = FindNextFile(hFind, &wfd);
  57.     }
  58.     if (GetLastError() != ERROR_NO_MORE_FILES)
  59.     {
  60.         fprintf(stderr, "FindNextFile died for some reason; path = \"%s\"\n", path);
  61.         abort();
  62.     }
  63.     if (FindClose(hFind) == FALSE)
  64.     {
  65.         fprintf(stderr, "FindClose failed\n");
  66.         abort();
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement