Professional Web Applications Themes

File.expand_path and ~ on windows - Ruby

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 ...

  1. #1

    Default File.expand_path and ~ on windows

    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 Guest

  2. #2

    Default Re: File.expand_path and ~ on windows

    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 Doents (C:\Doents and
    Settings\Username\My Doents on WinXP)? I suppose it would be
    worthwhile to be able to disable it, though.

    --
    Tom Felker, <tcfelkermtco.com>
    <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 Guest

  3. #3

    Default Re: File.expand_path and ~ on windows

    On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    > Wouldn't it make more sense to expand it to My Doents (C:\Doents
    > and Settings\Username\My Doents on WinXP)? I suppose it would be
    > worthwhile to be able to disable it, though.
    No. ~ has no meaning to Windows shells. There are times when I wish that it
    didn't to Unix shells. After all, that's what ${HOME} is for.

    -austin
    --
    austin ziegler * [email]austinhalostatue.ca[/email] * Toronto, ON, Canada
    software designer * pragmatic programmer * 2003.09.18
    * 23.12.23



    Austin Ziegler Guest

  4. #4

    Default Re: File.expand_path and ~ on windows

    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 Doents (C:\Doents and
    > Settings\Username\My Doents on WinXP)? I suppose it would be
    > worthwhile to be able to disable it, though.
    Actually, I think it should just expand to C:\Doents and
    Settings\UserName and you can append the rest from there. That's the
    *nix equivalent pretty much.

    Sean O'Dell

    Sean O'Dell Guest

  5. #5

    Default Re: File.expand_path and ~ on windows

    Austin Ziegler wrote:
    > On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    >
    >>Wouldn't it make more sense to expand it to My Doents (C:\Doents
    >>and Settings\Username\My Doents on WinXP)? I suppose it would be
    >>worthwhile to be able to disable it, though.
    >
    >
    > No. ~ has no meaning to Windows shells. There are times when I wish that it
    > didn't to Unix shells. After all, that's what ${HOME} is for.
    This is true; but I think for portability reasons, since COMMAND.COM
    isn't exactly what I would call a culture of shell idioms, ~ and ${HOME}
    (%HOME%) should be considered synonymous. If not ~, then at least
    ${HOME} ought to point to C:\Doents and Settings\UserName I think.

    Sean O'Dell

    Sean O'Dell Guest

  6. #6

    Default Re: File.expand_path and ~ on windows

    > -----Original Message-----
    > From: Sean O'Dell [mailto:seancSePlsoAfMt.com[REMOVE_THE_SPAM]]
    > Sent: Friday, September 19, 2003 10:19 AM
    > To: [email]ruby-talkruby-lang.org[/email]
    > Subject: Re: File.expand_path and ~ on windows
    >
    >
    > Austin Ziegler wrote:
    >
    > > On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    > >
    > >>Wouldn't it make more sense to expand it to My Doents
    > (C:\Doents
    > >>and Settings\Username\My Doents on WinXP)? I suppose it
    > would be
    > >>worthwhile to be able to disable it, though.
    > >
    > >
    > > No. ~ has no meaning to Windows shells. There are times when I wish
    > > that it
    > > didn't to Unix shells. After all, that's what ${HOME} is for.
    >
    > This is true; but I think for portability reasons, since COMMAND.COM
    > isn't exactly what I would call a culture of shell idioms, ~
    > and ${HOME}
    > (%HOME%) should be considered synonymous. If not ~, then at least
    > ${HOME} ought to point to C:\Doents and Settings\UserName I think.
    >
    > Sean O'Dell
    FWIW, it is possible to set a HOME directory. On XP Pro: Control Panel ->
    User Accounts -> Advanced -> Users.

    Then, right click on a given user and click "properties" and click the
    "profile" tab. There you should see a "home folder" option. This is what
    sets the LPUSER_INFO_11 struct value for the usri11_home_dir member.

    So, in theory you can get a user's home dir like this:

    # Available on RAA - shameless plug
    require "sys/win32etc"
    include Sys

    home = Win32Etc.getpwnam("some_user").home_dir

    However, it seems that in practice this value is rarely set (it wasn't in
    any of the 3 machines that I tested) and that %HOME% should be the first
    default.

    Regards,

    Dan

    Berger, Daniel Guest

  7. #7

    Default Re: File.expand_path and ~ on windows

    Berger, Daniel wrote:
    >>-----Original Message-----
    >>From: Sean O'Dell [mailto:seancSePlsoAfMt.com[REMOVE_THE_SPAM]]
    >>Sent: Friday, September 19, 2003 10:19 AM
    >>To: [email]ruby-talkruby-lang.org[/email]
    >>Subject: Re: File.expand_path and ~ on windows
    >>
    >>
    >>Austin Ziegler wrote:
    >>
    >>
    >>>On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    >>>
    >>>
    >>>>Wouldn't it make more sense to expand it to My Doents
    >>
    >>(C:\Doents
    >>
    >>>>and Settings\Username\My Doents on WinXP)? I suppose it
    >>
    >>would be
    >>
    >>>>worthwhile to be able to disable it, though.
    >>>
    >>>
    >>>No. ~ has no meaning to Windows shells. There are times when I wish
    >>>that it
    >>>didn't to Unix shells. After all, that's what ${HOME} is for.
    >>
    >>This is true; but I think for portability reasons, since COMMAND.COM
    >>isn't exactly what I would call a culture of shell idioms, ~
    >>and ${HOME}
    >>(%HOME%) should be considered synonymous. If not ~, then at least
    >>${HOME} ought to point to C:\Doents and Settings\UserName I think.
    >>
    >> Sean O'Dell
    >
    >
    > FWIW, it is possible to set a HOME directory. On XP Pro: Control Panel ->
    > User Accounts -> Advanced -> Users.
    >
    > Then, right click on a given user and click "properties" and click the
    > "profile" tab. There you should see a "home folder" option. This is what
    > sets the LPUSER_INFO_11 struct value for the usri11_home_dir member.
    >
    > So, in theory you can get a user's home dir like this:
    >
    > # Available on RAA - shameless plug
    > require "sys/win32etc"
    > include Sys
    >
    > home = Win32Etc.getpwnam("some_user").home_dir
    >
    > However, it seems that in practice this value is rarely set (it wasn't in
    > any of the 3 machines that I tested) and that %HOME% should be the first
    > default.
    That's interesting; it's there in Win2k as well.

    I would say (in agreement) that ~ should first be wherever %HOME% points
    to, then wherever the home directory is set in the registry (if it's not
    an empty/whitespace-filled string) and THEN C:\Doents and
    Settings\UserName after that. /whew

    Sean O'Dell

    Sean O'Dell Guest

  8. #8

    Default Re: File.expand_path and ~ on windows

    On Sat, 20 Sep 2003 01:18:35 +0900, Sean O'Dell wrote:
    > Austin Ziegler wrote:
    >> On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    >>> Wouldn't it make more sense to expand it to My Doents
    >>> (C:\Doents and Settings\Username\My Doents on WinXP)? I
    >>> suppose it would be worthwhile to be able to disable it, though.
    >> No. ~ has no meaning to Windows shells. There are times when I wish
    >> that it didn't to Unix shells. After all, that's what ${HOME} is for.
    > This is true; but I think for portability reasons, since COMMAND.COM
    > isn't exactly what I would call a culture of shell idioms, ~ and ${HOME}
    > (%HOME%) should be considered synonymous. If not ~, then at least
    > ${HOME} ought to point to C:\Doents and Settings\UserName I think.
    That's a no fly zone, as far as I'm concerned. My %HOME% is not the same as
    my %USERPROFILE%. Further, ~foo is a valid filename on Windows. (It's valid
    in Unix, too, but you have to do \~foo to get it to work from the shell.)

    I'd like to see Ruby handle this right on each platform.

    -austin
    --
    austin ziegler * [email]austinhalostatue.ca[/email] * Toronto, ON, Canada
    software designer * pragmatic programmer * 2003.09.19
    * 13.23.38



    Austin Ziegler Guest

  9. #9

    Default Re: File.expand_path and ~ on windows

    On Sat, 20 Sep 2003 01:45:14 +0900, Berger, Daniel wrote:
    > FWIW, it is possible to set a HOME directory. On XP Pro:
    > Control Panel -> User Accounts -> Advanced -> Users.
    >
    > Then, right click on a given user and click "properties" and click the
    > "profile" tab. There you should see a "home folder" option. This is
    > what sets the LPUSER_INFO_11 struct value for the usri11_home_dir member.
    >
    > So, in theory you can get a user's home dir like this:
    >
    >
    > # Available on RAA - shameless plug
    > require "sys/win32etc"
    > include Sys
    >
    > home = Win32Etc.getpwnam("some_user").home_dir
    >
    > However, it seems that in practice this value is rarely set (it wasn't in
    > any of the 3 machines that I tested) and that %HOME% should be the first
    > default.
    In Windows, %HOME% is replaced with %USERPROFILE%.

    The "home dir" that you found is related to domain controllers (Windows NT
    networking).

    -austin
    --
    austin ziegler * [email]austinhalostatue.ca[/email] * Toronto, ON, Canada
    software designer * pragmatic programmer * 2003.09.19
    * 13.28.35



    Austin Ziegler Guest

  10. #10

    Default Re: File.expand_path and ~ on windows

    On Saturday, September 20, 2003, 2:18:35 AM, Sean wrote:
    > Austin Ziegler wrote:
    >> On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    >>
    >>>Wouldn't it make more sense to expand it to My Doents (C:\Doents
    >>>and Settings\Username\My Doents on WinXP)? I suppose it would be
    >>>worthwhile to be able to disable it, though.
    >>
    >>
    >> No. ~ has no meaning to Windows shells. There are times when I wish that it
    >> didn't to Unix shells. After all, that's what ${HOME} is for.
    > This is true; but I think for portability reasons, since COMMAND.COM
    > isn't exactly what I would call a culture of shell idioms, ~ and ${HOME}
    > (%HOME%) should be considered synonymous. If not ~, then at least
    > ${HOME} ought to point to C:\Doents and Settings\UserName I think.
    I use Windows, and choose to set HOME to D:/home/gavin, so that
    Windows and Cygwin can be in agreement. Certain Windows programs will
    make use of any %HOME% setting.

    Gavin


    Gavin Sinclair Guest

  11. #11

    Default Re: File.expand_path and ~ on windows

    > -----Original Message-----
    > From: Berger, Daniel [mailto:djbergeqwest.com]
    > Sent: Friday, September 19, 2003 10:45 AM
    > To: [email]ruby-talkruby-lang.org[/email]
    > Subject: Re: File.expand_path and ~ on windows
    >
    >
    > > -----Original Message-----
    > > From: Sean O'Dell [mailto:seancSePlsoAfMt.com[REMOVE_THE_SPAM]]
    > > Sent: Friday, September 19, 2003 10:19 AM
    > > To: [email]ruby-talkruby-lang.org[/email]
    > > Subject: Re: File.expand_path and ~ on windows
    > >
    > >
    > > Austin Ziegler wrote:
    > >
    > > > On Fri, 19 Sep 2003 11:36:28 +0900, Tom Felker wrote:
    > > >
    > > >>Wouldn't it make more sense to expand it to My Doents
    > > (C:\Doents
    > > >>and Settings\Username\My Doents on WinXP)? I suppose it
    > > would be
    > > >>worthwhile to be able to disable it, though.
    > > >
    > > >
    > > > No. ~ has no meaning to Windows shells. There are times
    > when I wish
    > > > that it
    > > > didn't to Unix shells. After all, that's what ${HOME} is for.
    I was doing some more research on porting some Perl Win32 modules when I
    came across this page:

    [url]http://www.roth.net[/url]

    Roth consulting has several Win32 modules that are NOT on CPAN. One of the
    things they also have is a ~home ISAPI filter. You can read about it here:

    [url]http://www.roth.net/ISAPI/Home/[/url]

    Anyway, it's another option to consider.

    Regards,

    Dan

    Berger, Daniel Guest

  12. #12

    Default Re: File.expand_path and ~ on windows

    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 Doents (C:\Doents
    >> and
    >> Settings\Username\My Doents on WinXP)? I suppose it would be
    >> worthwhile to be able to disable it, though.
    >
    >
    > Actually, I think it should just expand to C:\Doents 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:/Doents and Settings/foo"

    Alan.

    Alan Davies Guest

Similar Threads

  1. Open a flash file from another file in seperate windows.
    By Shawn Centers in forum Macromedia Flash
    Replies: 0
    Last Post: October 31st, 02:30 AM
  2. [BUG] File.expand_path regression in 1.8.0
    By Yukihiro Matsumoto in forum Ruby
    Replies: 1
    Last Post: August 23rd, 03:14 PM
  3. .fla File in Windows
    By Vincenzo webforumsuser@macromedia.com in forum Macromedia Flash Sitedesign
    Replies: 4
    Last Post: August 4th, 12:44 PM
  4. file and settings transfer Windows XP - windows ME
    By Josh in forum Windows Networking
    Replies: 1
    Last Post: July 11th, 09:28 AM
  5. Windows XP Folder/File Encryption removal after Windows XP re-install
    By Salvatore in forum Windows Setup, Administration & Security
    Replies: 1
    Last Post: July 8th, 11:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139