Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > File.expand_path and ~ on windows

Reply
Thread Tools

File.expand_path and ~ on windows

 
 
Alan Davies
Guest
Posts: n/a
 
      09-18-2003
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.

 
Reply With Quote
 
 
 
 
Tom Felker
Guest
Posts: n/a
 
      09-19-2003
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.

 
Reply With Quote
 
 
 
 
Alan Davies
Guest
Posts: n/a
 
      09-22-2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Windows logon Screen in Windows 7 and Windows 2008 Tech Guy Windows 64bit 0 04-27-2011 12:59 PM
!Windows Live Mail replace Outlook Express on Windows XP and Windows Mail on Vista... Max Burke NZ Computing 8 05-18-2007 12:10 AM
Windows xp and windows 64bit and games. =?Utf-8?B?QXRvbA==?= Windows 64bit 10 12-05-2005 08:28 PM
wireless ad-hoc with Windows XP and Windows 2000 =?Utf-8?B?ZHVtbWthdWY=?= Wireless Networking 1 09-23-2004 11:34 AM
Windows XP laptop and Windows 2000 desktop won't communicate =?Utf-8?B?UmlmbGVtYW4=?= Wireless Networking 0 08-19-2004 03:35 AM



Advertisments
 



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