Xref: utzoo comp.sys.att:2909 comp.sys.misc:1320 Path: utzoo!utgpu!water!watmath!clyde!att-cb!att-ih!pacbell!ames!nrl-cmf!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!cornell!rochester!udel!burdvax!uucsbb!des From: des@uucsbb.UUCP (Don Shope) Newsgroups: comp.sys.att,comp.sys.misc Subject: Re: Seeking a method to "read" a DOS directory Summary: Microsoft C 5.0 code included Message-ID: <285@uucsbb.UUCP> Date: 31 Mar 88 16:55:55 GMT References: <902@cblpe.ATT.COM> <1001@mcgill-vision.UUCP> Reply-To: des@uucsbb.Blue Bell.UNISYS.COM (Don Shope) Organization: Unisys Unix Support Services, Blue Bell, PA Lines: 63 In article <902@cblpe.ATT.COM>, jrm@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 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.