Re: dospath.py anyone?

Bennett Todd (bet@std.sbi.com)
Tue, 21 Dec 1993 12:54:20 -0500 (EST)

>For example, should a pathname like "A:foo" be considered absolute or
>not?

I don't (yet, I hope to change this!) know Python well enough to do up a
dospath for you, but I can precisely describe the user (and syscall)
semantics of DOS pathnames.

DOS keeps a current selected drive. For each drive it keeps a current
working directory. So the sequence:

C>cd a:\foo
C>

leaves you with your current selected drive still C:, and your current
working directory on C unchanged, but it changes your current working
directory on A:. A subsequent

C>dir a:

or

C>a:
A>cd

would show that the current default on A: has been changed. DOS notices when
a disk changes (by some heuristics using the volume label and fat info) and
purges its old notion of that drives cwd on media change.

The command to change current working directory, CD, is independant of (and
doesn't overlap functionality with) the commands A:,B:,C:, etc. to change
currently selected drive.

The upshot of all this is that to parse a pathname, you strip off any
leading [a-z]: drive designation, then look for a leading separator. If that
separator is missing the path is relative to the cwd on that drive; and if
there was no drive designator than the path is relative to the current
drive. I guess its a matter of terminology, but I don't think it would be
wrong to say that an absolute pathname matches

^[a-zA-Z]:[\\/]

On the other hand, you might want to ignore the multi-drive support in DOS,
leaving a model that's more simply harmonious with Unix. In which case, an
absolute pathname must match

^([a-zA-Z]:)?[\\/]

I'd say operations like dirname would leave the drive designator attached to
the root, or the first directory component.

Does any of this help?

-Bennett
bet@sbi.com