[comp.os.msdos.programmer] Can I read a subdirectory file ?

fester@wolf.cs.washington.edu (Lea Fester) (12/24/90)

I'd like to read a subdirectory file as a file, but of course DOS
won't Open a file with the directory attribute set, and neither can
you change that attribute using the correct DOScall (so I can't
temporarily reset and then set that attribute.)

Am I forced to go to the FAT to chase down the cluster chain doing
raw disk reads, or does someone know of a way to trick DOS into 
letting you read a subdirectory as a file ?  I'd like to have some
of the amenities of file-handling OS functions available for use,
if there were a way to trick DOS into treating a subdirectory like
a regular file.

LeaF

vgopal@cbnewsc.att.com (venu.p.gopal) (12/29/90)

In article <14237@june.cs.washington.edu>, fester@wolf.cs.washington.edu (Lea Fester) writes:
! I'd like to read a subdirectory file as a file, but of course DOS
! won't Open a file with the directory attribute set, and neither can
! you change that attribute using the correct DOScall (so I can't
> temporarily reset and then set that attribute.)
> 
> Am I forced to go to the FAT to chase down the cluster chain doing

I believe you can do this through the use of FCBs (pre 2.00 DOS style)
and not through handles.  Haven't done this myself, so I am not speaking
from experience.

I don't know why you need to read the sub-directory as a file (unless you
are looking for the specific locations of the files contained) - most
things, you can get by by using a combination of the functions:

	rename file (will move files between directories)
	create/delete/read/write files
	create/delete directories

Venu P. Gopal   UUCP: ..!att!cbnewsc!vgopal   Internet: vgopal@cbnewsc.att.com

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (12/29/90)

In article <1990Dec28.174004.12184@cbnewsc.att.com> vgopal@cbnewsc.att.com (venu.p.gopal) writes:
>In article <14237@june.cs.washington.edu>, fester@wolf.cs.washington.edu (Lea Fester) writes:
>! I'd like to read a subdirectory file as a file, but of course DOS
>! won't Open a file with the directory attribute set, and neither can
>! you change that attribute using the correct DOScall (so I can't
>> temporarily reset and then set that attribute.)
>> 
>> Am I forced to go to the FAT to chase down the cluster chain doing
>
>I believe you can do this through the use of FCBs (pre 2.00 DOS style)
>and not through handles.  Haven't done this myself, so I am not speaking
>from experience.

I think the FCB method was a bug in DOS that got fixed.  It apparently worked
in DOS 2.X and maybe some early 3.X versions, but doesn't work in 3.2.  I'd
guess it won't work in higher versions either.

Chasing down the FAT is probably the only reliable way to go.

Duncan Murdoch

ts@uwasa.fi (Timo Salmi) (12/30/90)

In article <1990Dec29.152859.25732@maytag.waterloo.edu> dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
>In article <1990Dec28.174004.12184@cbnewsc.att.com> vgopal@cbnewsc.att.com (venu.p.gopal) writes:
>>In article <14237@june.cs.washington.edu>, fester@wolf.cs.washington.edu (Lea Fester) writes:
>>! I'd like to read a subdirectory file as a file, but of course DOS
>>! won't Open a file with the directory attribute set, and neither can
>>! you change that attribute using the correct DOScall (so I can't
>>> temporarily reset and then set that attribute.)
... rest deleted ...

I don't quite understand this.  Why can't one change the
subdirectory file attribute temporarily not to be directory, do
one's reading and change it back.  Or to be on the safe side, copy
the file, change back and then browse the copied file.  Turbo Pascal
at least should have the facilities to do this.  I have to admit,
though, that this is partly guesswork on my part, since I have not
tried out exactly this procedure, but only something similar for a
slightly different purpose.  (Of course it would be relatively easy
to test whether this is so, or not.)

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (12/31/90)

In article <1990Dec29.195859.28295@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
>
>I don't quite understand this.  Why can't one change the
>subdirectory file attribute temporarily not to be directory, do
>one's reading and change it back.  Or to be on the safe side, copy
>the file, change back and then browse the copied file.  Turbo Pascal
>at least should have the facilities to do this.  I have to admit,
>though, that this is partly guesswork on my part, since I have not
>tried out exactly this procedure, but only something similar for a
>slightly different purpose.  (Of course it would be relatively easy
>to test whether this is so, or not.)

There are two problems:  First, the legal DOS calls don't let you touch the
Subdirectory bit in the attributes byte.  I don't know if undocumented ones
would let you, but tend to doubt it:  you probably just have to go in at the
sector level to make the change.  

The second problem is that a directory
entry for a subdirectory always has the length field set to 0.  The only
way to know how long the directory is is to trace through it until you
get to an unused entry, or the end of the chain of clusters that make it up.
I've never understood the reason for this, but it means that if you just
turn off the Subdirectory bit, you'll end up with a zero length file and
won't be able to read it.

Duncan Murdoch

madams@ecst.csuchico.edu (Michael E. Adams) (12/31/90)

The folks who make the norton utilities seem to be able to read a directory
entry with no problem.  Can someone on the net find out how reach 
them and ask how they do it?

ts@uwasa.fi (Timo Salmi) (01/01/91)

In article <1990Dec29.195859.28295@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
>
>I don't quite understand this.  Why can't one change the
>subdirectory file attribute temporarily not to be directory, do
>one's reading and change it back.  Or to be on the safe side, copy
>the file, change back and then browse the copied file.  Turbo Pascal
>at least should have the facilities to do this.  I have to admit,
>though, that this is partly guesswork on my part, since I have not
>tried out exactly this procedure, but only something similar for a
>slightly different purpose.  (Of course it would be relatively easy
>to test whether this is so, or not.)

I have now tested this, and my guesswork was wrong.  Simple as that. 
Turbo Pascal's SetFAttr won't properly reset a directory attribute
even if it resets the others.

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun