File.expand_path and ~ on windows

A

Alan Davies

From the pickaxe book...
File.expand_path( fileName [, aDirString ] ) -> fileName
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.
 
T

Tom Felker

From the pickaxe book...
File.expand_path( fileName [, aDirString ] ) -> fileName
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, <[email protected]>
<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.
 
A

Alan Davies

Sean said:
Tom said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top