[comp.windows.ms.programmer] DOS dir command - How does it work?

karl@polyof.poly.edu (Karl H. Muhlbach, Staff) (11/20/90)

Dear Fellow Netters:

	I am writing a little utility but I need to get some
insight on something.  I was wondering how DOS accomplishes the dir command.
Is it done via the DOS system calls or is it bios related?  The reason I
ask is that part of my utility is to read a diskette and reference every
file on the diskette to see its file attributes (ie. size, date,
permissions, etc.). Unlike DOS I need to traverse the tree structure to
recursively reference every file.  DOS will only indicate that a
particular file is a subdirectory and not change dir to reference the files
in it.  I was considering using the ftw (file tree walk) system call but
was concerned about the max. open file limitation of 20.  Could anyone shed
some light on this for me.  This aspect and its speed performance are the
only things holding back the efficient completion of the utility.  I have
it working with referencing the disk using the ftw call but there must be a
more efficient and quicker method.

	I would greatly appreciate any help that might be sent my way.
Please EMail me any responses so that I may have a quicker turn around time
on an answer since I do not get much time to read news.  Also, if your
response is to RTFM then fine, point me in the direction of a decent book
on DOS internals and I will RTFM! The books I have seen do not go into
stuff like this.

					Thanks to all
					in advance!

						Karl M.


-- 
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Karl H. Muhlbach   	Email: karl@polyof.poly.edu
			Voice: (516) 794-0142
			  FAX: (516) 794-0142  

c164-bd@cinna.uucp (John D. Mitchell) (11/20/90)

In article <1990Nov19.212134.6012@polyof.poly.edu> karl@polyof.poly.edu (Karl H. Muhlbach, Staff) writes:
>

>	I am writing a little utility but I need to get some
>insight on something.  I was wondering how DOS accomplishes the dir command.
>Is it done via the DOS system calls or is it bios related?  The reason I

Dir is a built in command for command.com.  Who knows what it does?

>ask is that part of my utility is to read a diskette and reference every
>file on the diskette to see its file attributes (ie. size, date,
>permissions, etc.). Unlike DOS I need to traverse the tree structure to
>recursively reference every file.  DOS will only indicate that a
>particular file is a subdirectory and not change dir to reference the files

Use the DOS functions FindFirst and FindNext.  When you find a 'file' with
it's directory attribute then you do another (recursive) walk of that
directory.  Any decent DOS internals book will have the calling information
for them.

>some light on this for me.  This aspect and its speed performance are the
>only things holding back the efficient completion of the utility.  I have
>it working with referencing the disk using the ftw call but there must be a
>more efficient and quicker method.

Speed should be sufficient using the above method.

Good luck,
	John D. Mitchell
	johnm@cory.Berkeley.EDU

lorena@informix.com (Lon Anderson) (11/21/90)

karl@polyof.poly.edu (Karl H. Muhlbach, Staff) writes:


>Dear Fellow Netters:

>	I am writing a little utility but I need to get some
>insight on something.  I was wondering how DOS accomplishes the dir command.
>Is it done via the DOS system calls or is it bios related?  The reason I
>ask is that part of my utility is to read a diskette and reference every
>file on the diskette to see its file attributes (ie. size, date,
>permissions, etc.). Unlike DOS I need to traverse the tree structure to
>recursively reference every file.  DOS will only indicate that a
>particular file is a subdirectory and not change dir to reference the files
>in it.  I was considering using the ftw (file tree walk) system call but
>was concerned about the max. open file limitation of 20.  Could anyone shed
>some light on this for me.  This aspect and its speed performance are the
>only things holding back the efficient completion of the utility.  I have
>it working with referencing the disk using the ftw call but there must be a
>more efficient and quicker method.

>	I would greatly appreciate any help that might be sent my way.
>Please EMail me any responses so that I may have a quicker turn around time
>on an answer since I do not get much time to read news.  Also, if your
>response is to RTFM then fine, point me in the direction of a decent book
>on DOS internals and I will RTFM! The books I have seen do not go into
>stuff like this.

>					Thanks to all
>					in advance!

>						Karl M.


>-- 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  Karl H. Muhlbach   	Email: karl@polyof.poly.edu
>			Voice: (516) 794-0142
>			  FAX: (516) 794-0142  

The DOS dir command uses the FCB FindFirst and FindNext int 21h functions.

Lon Anderson

valley@uchicago (Doug Dougherty) (11/27/90)

karl@polyof.poly.edu (Karl H. Muhlbach, Staff) writes:


>Dear Fellow Netters:

>	I am writing a little utility but I need to get some
> ...
>in it.  I was considering using the ftw (file tree walk) system call but
> ...

File tree walk system call?  In DOS???  What that?

bernt@wolfen.cc.uow.oz (Bernt Ribbum) (11/27/90)

valley@uchicago (Doug Dougherty) writes:

>File tree walk system call?  In DOS???  What that?

Maybe something like this (Turbo C):

#include <dir.h>

	int done;
	struct ffblk ffblk;
	char *filespec;

	done = findfirst(filespec,&ffblk,
		FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_DIREC | FA_ARCH);

	while (!done)
	{
		/* do whatever... */

		done = findnext(&ffblk);
	}

Leaving out any of the constants FA_... will exclude files with the
corresponding attributes set.

-- 
 _--_|\    -- Bernt Ribbum, Dept of Elec & Comp Eng, Univ of Wollongong
/      \   -- PO.Box 1144, Wollongong NSW 2500, AUSTRALIA  ------------
\_.--._/   -- bernt@wolfen.cc.uow.edu.au  -----------------------------
      v
-- 
 _--_|\    -- Bernt Ribbum, Dept of Elec & Comp Eng, Univ of Wollongong
/      \   -- PO.Box 1144, Wollongong NSW 2500, AUSTRALIA  ------------
\_.--._/   -- bernt@wolfen.cc.uow.edu.au  -----------------------------
      v