home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / msdos / programm / 11640 < prev    next >
Encoding:
Internet Message Format  |  1992-12-27  |  1.9 KB

  1. Path: sparky!uunet!ogicse!uwm.edu!spool.mu.edu!umn.edu!staff.tc.umn.edu!wright
  2. From: wright@staff.tc.umn.edu (Mark Wright)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: FAQ listDir(char* path);
  5. Message-ID: <1992Dec27.193532.18961@news2.cis.umn.edu>
  6. Date: 27 Dec 92 19:35:32 GMT
  7. Article-I.D.: news2.1992Dec27.193532.18961
  8. References: <1992Dec24.224711.26356@coe.montana.edu>
  9. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  10. Organization: University of Minnesota
  11. Lines: 61
  12. Nntp-Posting-Host: staff.tc.umn.edu
  13.  
  14. You're not blind, no such function is provided.  Here are two that I use.
  15. Note that files is an array of char *, and actually allocating the space
  16. each char * points to is done in the function.  So, that space must be
  17. free()'ed later.
  18.  
  19. /****************** FILE LIST **********************************************/
  20.  
  21. int file_list( char *files[], char *path )
  22.  
  23. {
  24.   struct ffblk file_info;
  25.   int i;
  26.  
  27.   i = 0;
  28.   if (findfirst( path, &file_info, FA_ARCH ) == 0) {
  29.     files[i++] = strdup( file_info.ff_name );
  30.     assert( files[i-1]  );
  31.     while (findnext( &file_info ) == 0) {
  32.       files[i++] = strdup( file_info.ff_name );
  33.       assert( files[i-1]  );
  34.     }
  35.   }
  36.  
  37.   return i;
  38. }
  39.  
  40. /****************** FILE LIST **********************************************/
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /****************** DIR LIST ***********************************************/
  47.  
  48. int dir_list( char *files[], char *path )
  49.  
  50. {
  51.   struct ffblk file_info;
  52.   int i;
  53.  
  54.   i = 0;
  55.   if (findfirst( path, &file_info, FA_DIREC ) == 0) {
  56.     if (file_info.ff_attrib == FA_DIREC) {
  57.       files[i++] = strdup( file_info.ff_name );
  58.       assert( files[i-1]  );
  59.     }
  60.     while (findnext( &file_info ) == 0)
  61.       if (file_info.ff_attrib == FA_DIREC) {
  62.         files[i++] = strdup( file_info.ff_name );
  63.         assert( files[i-1]  );
  64.       }
  65.   }
  66.  
  67.   return i;
  68. }
  69.  
  70. /****************** DIR LIST ***********************************************/
  71.  
  72. -- 
  73. Mark Wright
  74. wright@epx.cis.umn.edu
  75.