delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/07/28/11:19:13

Date: Fri, 28 Jul 1995 17:25:40 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
Cc: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Subject: Re: Reading a directory as if it was a file

On Thu, 27 Jul 1995, A.Appleyard wrote:

>   Is there any way in (interrupts usable under Gnu C) to read a directory as
> if it was a file? I want to write my own program to explore directories. I
> tried this method in a Gnu C++ program:-

You can't.  DOS won't let you open() a directory no matter how hard you 
try.  There used to be a back door using the old FCB functions, but 
Microsoft shut it in MS-DOS 5.0.  I didn't read your program carefully 
enough to understand why you say you've succeeded in opening the 
directory; you should have got the carry bit set and an error code saying 
something like Access Denied.

To read the directory entries, you have these alternatives:

	1) Read the entire disk structure into memory, then read your 
directory at the BIOS level (by sectors).  This is what disk-repair 
programs like Norton Utilities do.

	2) Use the opendir()/readdir()/closedir() POSIX functions to get 
the file/subdirectory names, then call stat() to get the additional info 
about every file.

	3) Use the DOS FindFirst/FindNext functions to get all the info 
recorded in the directory entry (except the starting cluster number, 
which DOS for some reason won't disclose easily).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019