Modeling weird Windows pathnames

Discussion in 'Java' started by Ian Pilcher, Jan 27, 2006.

  1. Ian Pilcher

    Ian Pilcher Guest

    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

    --
    ========================================================================
    Ian Pilcher
    ========================================================================
    Ian Pilcher, Jan 27, 2006
    #1
    1. Advertising

  2. Ian Pilcher

    Oliver Wong Guest

    "Ian Pilcher" <> wrote in message
    news:...
    > 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
    Oliver Wong, Jan 27, 2006
    #2
    1. Advertising

  3. Ian Pilcher

    Ian Pilcher Guest

    Oliver Wong wrote:
    > 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!

    --
    ========================================================================
    Ian Pilcher
    ========================================================================
    Ian Pilcher, Jan 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Polak

    Relative Pathnames in an ASP program

    Ted Polak, Aug 12, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    331
    szabelin
    Aug 12, 2003
  2. Kevin Spencer

    favicon.ico and long pathnames

    Kevin Spencer, Jan 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    417
  3. Replies:
    6
    Views:
    484
  4. tenxian
    Replies:
    2
    Views:
    422
    Arne Vajhøj
    Apr 8, 2008
  5. Clifford Heath
    Replies:
    2
    Views:
    187
    Clifford Heath
    Feb 7, 2007
Loading...

Share This Page