Seeking a method to "read" a DOS directory

Pete Fales psfales at ihlpe.ATT.COM
Sat Feb 13 01:12:35 AEST 1988


In article <902 at cblpe.ATT.COM>, jrm at cblpe.ATT.COM (John Miller) writes:
> I would like obtain a list of files that are in a DOS directory using
> Microsoft 'C', version 4 or 5. Near as I can tell, you are not permitted
> to "open" a directory in dos. Further, I have not been able to find a
> function in the MSC library, or a function in the DOS or BIOS library
> that will permit me to find out what files are in a given directory.
> 
> The best method I know of so far (and this is more of an attack plan than
> a sure and tried solution) - is to use a DOS interrupt function to gain
> information about the FAT. From that information, I should be able to
> calculate the location, on disk, of the beginning sector containing
> the DOS directory table. Once in the table, I should be able to traverse
> through the chains to find all the files that are in the directory I
> am interested in.

There is a better way!  Some compilers have library routines to do this
(my Ecosoft compiler, for example) but that doesn't help you much if
yours doesn't.  Take a look at the DOS functions "find first" and "find
next."  These functions take a complete path name (including wild cards)
and return all files that match the template.  If you give it a path
name terminating in *.*, it will find all the files in the directory.
There are bits you can set in the paramter block to include/exclude
subdirectories and hidden or system files.  

This should do what you want in a much more device independent manner.

Pete
-- 
Peter Fales		UUCP:	...ihnp4!ihlpe!psfales
			work:	(312) 979-7784
				AT&T Information Systems, IW 1Z-243
				1100 E. Warrenville Rd., IL 60566



More information about the Comp.sys.att mailing list