home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: wright@staff.tc.umn.edu (Mark Wright)
- Subject: Re: Reading Filenames into an ARRAY
- Message-ID: <1992Nov18.220433.4235@news2.cis.umn.edu>
- Keywords: in MOSDOS, Borland C 3.1
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: staff.tc.umn.edu
- Organization: University of Minnesota
- References: <1992Nov18.164544.13273@netcom.com>
- Date: Wed, 18 Nov 1992 22:04:33 GMT
- Lines: 83
-
- In article <1992Nov18.164544.13273@netcom.com> bobb@netcom.com (Bob Beaulieu) writes:
- >I want to be able to display a list of specific files in the current
- >directory from within my program. I want to be able to allow users to
- >select from a list of these file to be acted upon (printed,deleted,...).
- >
- >Is there an easy way to do this? It has to be DOS 2.0+ and not a
- >windows application.
- >
- >Any helpful comments will be appreciated!
- >
- >Thanks,
- >
- >Bob Beaulieu
- >bobb@netcom.com
- >--
- > =============================================================
- > Bob Beaulieu bobb@netcom.com
- > San Jose, CA (408) 978-0818
- > =============================================================
-
- Here's what I use. The first will read in all files matching the file
- specifier in path (note: \name will look for a file named name in the root
- directory, it will not list the files in a directory \name). The second
- will provide the list of all the directories matching path.
- Also, when you are done with char *files[], be sure to free all the strings
- allocated by the functions. Enjoy.
-
- /****************** FILE LIST **********************************************/
-
- int file_list( char *files[], char *path )
-
- {
- struct ffblk file_info;
- int i;
-
- i = 0;
- if (findfirst( path, &file_info, FA_ARCH ) == 0) {
- files[i++] = strdup( file_info.ff_name );
- assert( files[i-1] );
- while (findnext( &file_info ) == 0) {
- files[i++] = strdup( file_info.ff_name );
- assert( files[i-1] );
- }
- }
-
- return i;
- }
-
- /****************** FILE LIST **********************************************/
-
-
-
-
-
- /****************** DIR LIST ***********************************************/
-
- int dir_list( char *files[], char *path )
-
- {
- struct ffblk file_info;
- int i;
-
- i = 0;
- if (findfirst( path, &file_info, FA_DIREC ) == 0) {
- if (file_info.ff_attrib == FA_DIREC) {
- files[i++] = strdup( file_info.ff_name );
- assert( files[i-1] );
- }
- while (findnext( &file_info ) == 0)
- if (file_info.ff_attrib == FA_DIREC) {
- files[i++] = strdup( file_info.ff_name );
- assert( files[i-1] );
- }
- }
-
- return i;
- }
-
- /****************** DIR LIST ***********************************************/
-
- --
- Mark Wright
- wright@epx.cis.umn.edu
-