Modeling weird Windows pathnames

I

Ian Pilcher

I'm working on a "tokenized path name" class, which will allow me to
manipulate file and directory paths more easily than java.io.File (or
java.lang.String). I've currently modeled a path as:

* An (optional) "filesystem root",
* Zero or more directory names, and
* An (optional) file name.

This works find in a UNIX (Linux) environment, and it works for most
paths on Windows. It breaks down, however, when fed what I call a
"semi-absolute" path on Windows -- a path that begins with a drive
letter but no backslash (C:foo) or a path that begins with a single
backslash (\foo).

I'm just wondering if anyone has any ideas on how to model these sorts
of paths.

TIA
 
O

Oliver Wong

Ian Pilcher said:
I'm working on a "tokenized path name" class, which will allow me to
manipulate file and directory paths more easily than java.io.File (or
java.lang.String). I've currently modeled a path as:

* An (optional) "filesystem root",
* Zero or more directory names, and
* An (optional) file name.

This works find in a UNIX (Linux) environment, and it works for most
paths on Windows. It breaks down, however, when fed what I call a
"semi-absolute" path on Windows -- a path that begins with a drive
letter but no backslash (C:foo) or a path that begins with a single
backslash (\foo).

I'm just wondering if anyone has any ideas on how to model these sorts
of paths.

TIA

Let's say this is the notation for a root "a" with 3 directory names "b",
"c" and "d", and a filename "e": ("a", "b", "c", "d", "e"). Here's the
notation for the same thing, but with the optional root ommited: (null, "b",
"c", "d", "e"). Similarly, for an omitted filename, ("a", "b", "c", "d",
null). We know that the first element is always the root, and the last
element is always the filename, and everything else must be directory names.

Linux: \usr\owong\Foo.java -> ("\", "\", "usr", "owong", "Foo.java")
Linux: owong\Foo.java -> (null, "owong", "Foo.java")
Windows: C:\Documents and Settings\owong\foo.java -> ("C:", "\", "Documents
and Settings", "owong", "foo.java")
Windows: owong\foo.java -> (null, "owong", "foo.java")
Windows: C:foo.java -> ("C:", "foo.java")
Windows: \foo.java -> (null, "\", "foo.java")

The idea is that in the most general case, you have a forest (i.e.
multiple trees), rather than a single rooted tree. The first element in the
list should indicate which tree you are dealing with (always "\" in the case
of Linux, but could be any drive letter in Windows). Every other element
should then be resolvable from your current location.

"\" always resolves to the root of the tree you're currently dealing
with, regardless of what the current location is. "a" should resolve to
whatever "a" is (either a directory or a file) in your current location.

So ("\", "\", "usr", "owong", "Foo.java") means: Use the tree known as "\"
(i.e. the Linux filesystem root), then resolve "\" in that tree (i.e. the
root of the filesystem), then resolve "usr" from there (the "usr" directory
in the root"), then resolve "owong" from there (the "owong" directory in the
"usr" directory) and so on.

(null, "owong", "foo.java") means the tree isn't specified, so used the
current tree, and then resolve "owong" from your current location in that
tree, and so on.

(null, "\", "foo.java") means the tree isn't specified, so used the current
tree, and then resolve "\" from your current location in that tree (and "\"
always resolves to the root of that tree), and so on.

- Oliver
 
I

Ian Pilcher

Oliver said:
The idea is that in the most general case, you have a forest (i.e.
multiple trees), rather than a single rooted tree. The first element in the
list should indicate which tree you are dealing with (always "\" in the case
of Linux, but could be any drive letter in Windows). Every other element
should then be resolvable from your current location.

Good stuff. I see now that I was conflating the idea of a "filesystem
root" with the idea of a root directory.

OTOH, I could just put everything in "My Computer".

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top