Advertisement
filip710

prvi

Apr 10th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. int main(int argc, char **argv)
  5. {
  6.  
  7.     int dirnum = 0;
  8.     int filenum = 0;
  9.     WIN32_FIND_DATA data;
  10.     HANDLE hFind = FindFirstFile("C:\\Users\\Filip\\Desktop\\root\\*", &data);      // DIRECTORY
  11.  
  12.     if (hFind == INVALID_HANDLE_VALUE)
  13.     {
  14.         fprintf(stderr, "FindFirstFile failed on path = \"%s\"\n", data.cFileName);
  15.         abort();
  16.     }
  17.     else {
  18.         do {
  19.             if ((strncmp(".", data.cFileName, 1) != 0) && (strncmp("..", data.cFileName, 2) != 0))
  20.                 {
  21.                     if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  22.                     {
  23.                         dirnum++;
  24.                     }
  25.                     else
  26.                     {
  27.                         filenum++;
  28.                
  29.                     }
  30.                 }
  31.         } while (FindNextFile(hFind, &data));
  32.         FindClose(hFind);
  33.     }
  34.  
  35.     printf("Num of dirs: %d\n", dirnum);
  36.     printf("Num of files: %d\n", filenum);
  37.  
  38.     system("pause");
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement