home *** CD-ROM | disk | FTP | other *** search
/ Programming Win32 Under the API / ProgrammingWin32UnderTheApiPatVillani.iso / Chapter5 / 5-2 / FindFile.c
C/C++ Source or Header  |  2000-07-14  |  655b  |  36 lines

  1.  
  2. #include <windows.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6.  
  7. BOOL main(INT argc, BYTE *argv[])
  8. {
  9.     WIN32_FIND_DATA  dmp;
  10.     HANDLE hDir;
  11.     BYTE szPattern[MAX_PATH];
  12.  
  13.     GetCurrentDirectory(MAX_PATH, szPattern);
  14.     strcat(szPattern, szPattern[strlen(szPattern)-1] == '\\'
  15.         ? "*.*" : "\\*.*");
  16.  
  17.     if((hDir = FindFirstFile((LPCTSTR)szPattern, (LPWIN32_FIND_DATA)&dmp))
  18.      == INVALID_HANDLE_VALUE)
  19.     {
  20.         printf("Directory error\nPattern: \"%s\"\n", szPattern);
  21.         return 1;
  22.     }
  23.  
  24.     do
  25.     {
  26.         printf("\n%s", dmp.cFileName);
  27.     }
  28.     while(FindNextFile((HANDLE)hDir, (LPWIN32_FIND_DATA)&dmp));
  29.  
  30.     printf("\n\n");
  31.     FindClose(hDir);
  32.     return 0;
  33. }
  34.  
  35.  
  36.