Mail Archives: djgpp/1995/07/28/11:19:13
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 -