Reading MS-DOS directory in C, how to

david nugent david at csource.oz.au
Thu Feb 15 16:12:21 AEST 1990


 > Message-ID: <1990Feb14.031640.28944 at usenet.ins.cwru.edu>
 >
 > I would like to read the current directory in a C program, but either
 > the books I have been reading (the Turbo C reference and my library of
 > beginner's books on the language) don't mention it, or I don't know
 > where in the index to look.  I assume there's some call that returns
 > an array of pointers to strings, but I really can't figure it out.


Hmm, no.

Turbo C should include a findfirst() and findnext() functions, which allow 
you to pass both a file "specification" and attributes. It's usually done 
something like this (node that the given path can include wildcards):


 .
 .
 #include <dos.h>
 #include <dir.h>
 .
 .
 .
 {
 int j;
 struct ffblk ff;       /* contains directory data */

 j = findfirst ("*.*", &ff, FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_DIREC);
 while (j)
      {
      /* store information or do whatever */
      j = findfirst (&ff);
      }
 .
 .


david

--  
uucp: ...!munnari!csource!david   
internet: david at csource.oz.au
Via FidoNet 3:632/348, Melbourne, Australia.



More information about the Comp.lang.c mailing list