Mail Archives: djgpp/2000/04/13/15:12:06
Gabriel Ortiz Lour <lour AT softone DOT com DOT br>:
> What is a good method for searching for files in a
given
> directory and for the directories in the root?
You can use findfirst/findnext functions, like this:
----- 8< -----
/* warning: untested code */
struct ffblk F;
int flag;
/* search for all .txt files in directory c:\mydir */
flag = findfirst("c:\\mydir\\*.txt", &F, 0);
while (!flag) {
// information for the file are in structure F
// do whatever you need...
printf("%s\n", F.ff_name);
flag = findnext(&F);
}
----- 8< -----
Iff you need to find all directories in the root you
replace the call to findfirt like this:
flag = findfirst("c:\\*.*", &F, FA_DIREC);
More info can be found in the C library documentation
(type "info libc alpha findfirst" at command prompt)
You can also look at function ftw(), which allows you
to traverse all sub-directories of a give directory,
like some sort of "recursive findfirst/next"
> When I found my self in trouble, someone came to me
with words of
> wisdom...
> write in C!
Write in C, yeah, Write in C.
BASIC's not the answer.
Write in C.
ciao
Giacomo
------------------------------------------------------
Giacomo Degli Esposti - pad2369 AT iperbole DOT bologna DOT it
- Raw text -