Article View: comp.os.msdos.programmer
Article #6197Re: FAQ listDir(char* path);
From: Mark Wright
Date: Sun, 27 Dec 1992 19:35
Date: Sun, 27 Dec 1992 19:35
61 lines
2033 bytes
2033 bytes
You're not blind, no such function is provided. Here are two that I use.
Note that files is an array of char *, and actually allocating the space
each char * points to is done in the function. So, that space must be
free()'ed later.
/****************** 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
Technical Details
Message-ID:
<1992Dec27.193532.18961@news2.cis.umn.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!spool.mu.edu!umn.edu!staff.tc.umn.edu!wrightReferences:
<1992Dec24.224711.26356@coe.montana.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!uwm.edu!spool.mu.edu!umn.edu!staff.tc.umn.edu!wright From: wright@staff.tc.umn.edu (Mark Wright) Newsgroups: comp.os.msdos.programmer Subject: Re: FAQ listDir(char* path); Message-ID: <1992Dec27.193532.18961@news2.cis.umn.edu> Date: 27 Dec 92 19:35:32 GMT Article-I.D.: news2.1992Dec27.193532.18961 References: <1992Dec24.224711.26356@coe.montana.edu> Sender: news@news2.cis.umn.edu (Usenet News Administration) Organization: University of Minnesota Lines: 61 Nntp-Posting-Host: staff.tc.umn.edu