Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Modeling weird Windows pathnames

Thread view: 
Ian Pilcher - 27 Jan 2006 15:32 GMT
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

Signature

========================================================================
Ian Pilcher                                        i.pilcher@comcast.net
========================================================================

Oliver Wong - 27 Jan 2006 17:39 GMT
> 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
[quoted text clipped - 14 lines]
>
> 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
Ian Pilcher - 27 Jan 2006 18:44 GMT
>     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!

Signature

========================================================================
Ian Pilcher                                        i.pilcher@comcast.net
========================================================================



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.