home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / sclib31 / examples / findfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-31  |  1.3 KB  |  52 lines

  1. #include <scl1.h>
  2.  
  3.   /**********************************************************
  4.     Shows the use of FindFirst/Next to get a directory list */
  5.  
  6. #define NO_MORE_FILES    18
  7.  
  8. static void printinfo(struct FileData *fd);
  9.  
  10. struct FileData fd; /* file info will be stored here */
  11.  
  12. main()
  13. {
  14. int RetVal;
  15.  
  16. RetVal=FindFirst("*.*",&fd,F_VOLUME);   /* read volume label */
  17. if(RetVal==NO_MORE_FILES)               /* no more files? */
  18.     printf("\nVolume has no label\n\n");
  19. else
  20.     printf("\nVolume label: %s\n\n",fd.name);
  21.  
  22.   /* read other files. Subdirectories, hidden, system and
  23.      archive files */
  24.  
  25. RetVal=FindFirst("*.*",&fd,F_DIRECTORY | F_SYSTEM | F_HIDDEN);
  26.  
  27.      /* Get filenames while no error is reported */
  28.  
  29. while(RetVal==0)
  30.     {
  31.     printinfo(&fd);      /* print file information */
  32.     RetVal=FindNext();   /* get next file */
  33.     }
  34. }
  35.  
  36. static void printinfo(struct FileData *fd)
  37. {
  38. printf("%-13s",fd->name); /* print file name */
  39.  
  40.      /* if file is not a directory, print file size */
  41.  
  42. if(fd->attrib == F_DIRECTORY)
  43.     printf("  <DIR>");
  44. else
  45.     printf("%7li",fd->size);
  46.  
  47. /* print date and time */
  48.  
  49. printf("  %.2i-%.2i-%.2i  %.2i:%.2i:%.2i\n",fd->date.month,
  50.            fd->date.day,fd->date.year+80,fd->time.hours,
  51.            fd->time.minutes, fd->time.seconds);
  52. }