File.expand_path and ~ on windows

Discussion in 'Ruby' started by Alan Davies, Sep 18, 2003.

  1. Alan Davies

    Alan Davies Guest

    From the pickaxe book...

    > File.expand_path( fileName [, aDirString ] ) -> fileName

    <snip>
    > The given pathname may start with a ``~'', which expands to the
    > process owner's home directory (the environment variable HOME must be
    > set correctly). "~ user" expands to the named user's home directory"


    This isn't relevant on windows. Thus:

    File.expand_path("~foo", "c:/somedir") -> "~foo"

    where in fact it should return "c:/somedir/~foo".

    Also:

    File.expand_path("~", "c:/somedir")

    throws up the error "`expand_path': couldn't find HOME environment --
    expanding `~' (ArgumentError)"

    It seems strange that the first example doesn't throw up the same error
    that the second one does.

    Can this functionality be disbaled on windows platforms in a future
    version? Or at least add a parameter to the function call to disable it?

    Alan.
    Alan Davies, Sep 18, 2003
    #1
    1. Advertising

  2. Alan Davies

    Tom Felker Guest

    On Thu, 18 Sep 2003 17:16:00 +0100, Alan Davies wrote:

    > From the pickaxe book...
    >
    > > File.expand_path( fileName [, aDirString ] ) -> fileName

    > <snip>
    > > The given pathname may start with a ``~'', which expands to the
    > > process owner's home directory (the environment variable HOME must be
    > > set correctly). "~ user" expands to the named user's home directory"

    >
    > This isn't relevant on windows. Thus:


    Wouldn't it make more sense to expand it to My Documents (C:\Documents and
    Settings\Username\My Documents on WinXP)? I suppose it would be
    worthwhile to be able to disable it, though.

    --
    Tom Felker, <>
    <http://vlevel.sourceforge.net> - Stop fiddling with the volume knob.

    You both prefer a universe in which the other party hasn't magically
    disappeared. I think we have a framework for peace.
    Tom Felker, Sep 19, 2003
    #2
    1. Advertising

  3. Alan Davies

    Alan Davies Guest

    Sean O'Dell wrote:
    > Tom Felker wrote:
    >
    >> On Thu, 18 Sep 2003 17:16:00 +0100, Alan Davies wrote:
    >>
    >>
    >>> From the pickaxe book...
    >>>
    >>> > File.expand_path( fileName [, aDirString ] ) -> fileName
    >>> <snip>
    >>> > The given pathname may start with a ``~'', which expands to the
    >>> > process owner's home directory (the environment variable HOME must be
    >>> > set correctly). "~ user" expands to the named user's home directory"
    >>>
    >>> This isn't relevant on windows. Thus:

    >>
    >>
    >>
    >> Wouldn't it make more sense to expand it to My Documents (C:\Documents
    >> and
    >> Settings\Username\My Documents on WinXP)? I suppose it would be
    >> worthwhile to be able to disable it, though.

    >
    >
    > Actually, I think it should just expand to C:\Documents and
    > Settings\UserName and you can append the rest from there. That's the
    > *nix equivalent pretty much.
    >
    > Sean O'Dell
    >


    Some interesting points being made on this thread, but the problem I had
    was that I has a files beginning with ~ in my temp folder. Using
    expand_path to get the full path of these files failed. If it expanded
    it to user directories, then it woulod be returning incrrect path names,
    simply because ~ has no meaning on windows.

    If I have a file called ~foo in a dir called "c:/somedir", then I would
    expand_path to return "c:/somedir/~foo", not "C:/Documents and Settings/foo"

    Alan.
    Alan Davies, Sep 22, 2003
    #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. John Platte

    File.expand_path(__FILE__)

    John Platte, Apr 29, 2004, in forum: Ruby
    Replies:
    29
    Views:
    373
    Robert Klemme
    May 3, 2004
  2. Erik Veenstra
    Replies:
    1
    Views:
    151
    Nobuyoshi Nakada
    Jun 3, 2008
  3. Fritz Anderson
    Replies:
    3
    Views:
    122
    Robert Dober
    Dec 9, 2008
  4. Roger Pack
    Replies:
    4
    Views:
    105
    Roger Pack
    May 30, 2009
  5. Alpha Blue
    Replies:
    25
    Views:
    269
    Robert Klemme
    Feb 5, 2010
Loading...

Share This Page