home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16742 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.9 KB  |  97 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!staff.tc.umn.edu!wright
  3. From: wright@staff.tc.umn.edu (Mark Wright)
  4. Subject: Re: Reading Filenames into an ARRAY
  5. Message-ID: <1992Nov18.220433.4235@news2.cis.umn.edu>
  6. Keywords: in MOSDOS, Borland C 3.1
  7. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  8. Nntp-Posting-Host: staff.tc.umn.edu
  9. Organization: University of Minnesota
  10. References: <1992Nov18.164544.13273@netcom.com>
  11. Date: Wed, 18 Nov 1992 22:04:33 GMT
  12. Lines: 83
  13.  
  14. In article <1992Nov18.164544.13273@netcom.com> bobb@netcom.com (Bob Beaulieu) writes:
  15. >I want to be able to display a list of specific files in the current
  16. >directory from within my program. I want to be able to allow users to
  17. >select from a list of these file to be acted upon (printed,deleted,...).
  18. >
  19. >Is there an easy way to do this? It has to be DOS 2.0+ and not a
  20. >windows application.
  21. >
  22. >Any helpful comments will be appreciated!
  23. >
  24. >Thanks,
  25. >
  26. >Bob Beaulieu
  27. >bobb@netcom.com
  28. >-- 
  29. > =============================================================
  30. > Bob Beaulieu                                 bobb@netcom.com  
  31. > San Jose, CA                                 (408) 978-0818  
  32. > =============================================================
  33.  
  34. Here's what I use.  The first will read in all files matching the file
  35. specifier in path (note: \name will look for a file named name in the root
  36. directory, it will not list the files in a directory \name).  The second
  37. will provide the list of all the directories matching path.
  38. Also, when you are done with char *files[], be sure to free all the strings
  39. allocated by the functions.  Enjoy.
  40.  
  41. /****************** FILE LIST **********************************************/
  42.  
  43. int file_list( char *files[], char *path )
  44.  
  45. {
  46.   struct ffblk file_info;
  47.   int i;
  48.  
  49.   i = 0;
  50.   if (findfirst( path, &file_info, FA_ARCH ) == 0) {
  51.     files[i++] = strdup( file_info.ff_name );
  52.     assert( files[i-1]  );
  53.     while (findnext( &file_info ) == 0) {
  54.       files[i++] = strdup( file_info.ff_name );
  55.       assert( files[i-1]  );
  56.     }
  57.   }
  58.  
  59.   return i;
  60. }
  61.  
  62. /****************** FILE LIST **********************************************/
  63.  
  64.  
  65.  
  66.  
  67.  
  68. /****************** DIR LIST ***********************************************/
  69.  
  70. int dir_list( char *files[], char *path )
  71.  
  72. {
  73.   struct ffblk file_info;
  74.   int i;
  75.  
  76.   i = 0;
  77.   if (findfirst( path, &file_info, FA_DIREC ) == 0) {
  78.     if (file_info.ff_attrib == FA_DIREC) {
  79.       files[i++] = strdup( file_info.ff_name );
  80.       assert( files[i-1]  );
  81.     }
  82.     while (findnext( &file_info ) == 0)
  83.       if (file_info.ff_attrib == FA_DIREC) {
  84.         files[i++] = strdup( file_info.ff_name );
  85.         assert( files[i-1]  );
  86.       }
  87.   }
  88.  
  89.   return i;
  90. }
  91.  
  92. /****************** DIR LIST ***********************************************/
  93.  
  94. -- 
  95. Mark Wright
  96. wright@epx.cis.umn.edu
  97.