[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File.expand_path and ~ on windows

Alan Davies

9/18/2003 4:16:00 PM

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.

3 Answers

Tom Felker

9/19/2003 2:19:00 AM

0

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, <tcfelker@mtco.com>
<http://vlevel.sourcefor... - 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.

Sean O'Dell

9/19/2003 3:58:00 PM

0

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

Alan Davies

9/22/2003 4:21:00 PM

0

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.