Seeking a method to "read" a DOS directory
Don Shope
des at uucsbb.UUCP
Fri Apr 1 02:55:55 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.
>
> The best method I know of so far [...] is to use a DOS interrupt
> function to gain information about the FAT. [and then read the disk
> to find the directory]
>
Following is a little program I wrote to illustrate the use of
two new functions in level 5.0 of the Microsoft C compiler:
/* Directory functions. The second argument to _dos_findfirst()
* specifies the necessary attributes needed for a file to be
* selected (whose name also matches the pattern). Values
* for attribute are: _A_NORMAL, _A_RDONLY, _A_HIDDEN, _A_SYSTEM,
* _A_VOLID, _A_SUBDIR, _A_ARCH (which can be or'd together).
* Return value is 0 upon success, errno is set on failure to ENOENT.
*
* Following is the function prototype and struct definition:
*
* unsigned _dos_findfirst(path,attributes,buffer);
* unsigned _dos_findnext(buffer);
* char *path; - target filename (* and ? allowed)
* unsigned attributes; - target attributes
* struct find_t {
* char reserved[21]; - reserved for use by MS-DOS
* char attrib; - attribute byte for matched path
* unsigned wr_time; - Time of last write to file
* unsigned wr_date; - Date of last write to file
* long size; - Length of file in bytes
* char name[13]; - filename/directory name
* } *buffer;
*/
#include <dos.h>
main(argc, argv)
int argc;
char *argv[];
{
struct find_t dosfile;
char pattern[81];
if( argc != 2 ) {
printf( "Enter DOS search pattern: " );
scanf( "%s", pattern );
}
else
strcpy( pattern, argv[1] );
printf( "Directory listing of '%s':\n\n", pattern );
if( _dos_findfirst( pattern, _A_NORMAL, &dosfile ) == 0 ) {
printf( "Size: %6ld File: %s\n", dosfile.size, dosfile.name );
while( _dos_findnext( &dosfile ) == 0 )
printf( "Size: %6ld File: %s\n", dosfile.size, dosfile.name );
}
else
printf( "Pattern '%s' not found.\n", pattern );
}
I hope this helps you out. Also, I am a new user, and I hope I have
done things correctly in this posting.
More information about the Comp.sys.att
mailing list