I’ve allways understood the ~ feature in some unix shells as being a
quick way of refering to a user’s home directory. I’m not familiar with
the idea you describe of ~ just indicating ‘the containing directory’.
I’ve never read up on this so I could be wrong but to me ‘~’ is related
to the (very UNIXish) concept of a home directory which, to me, doesn’t
seem to match to Windows particularly well.
Where would ‘home’ be on Windows? On Win2000 perhaps %USERPROFILE% but
I’m not sure this is defined for older versions of windows.
I agree it would be nice if file-handling facilities worked the same
regardless of platform, but I’m not sure how this particular feature
could be implemented across all flavours of Windows.
cheers,
Jon
···
-----Original Message-----
From: Grzegorz Chrupala [mailto:grzegorz@pithekos.net]
Sent: 17 June 2003 19:06
To: ruby-talk ML
Subject: Re: File.expand_path with files beginnig with ~ (tilde) on
Windoze
“Robert Klemme” bob.news@gmx.net wrote in message
news:bcmv8g$l5psh$1@ID-52924.news.dfncis.de…
Does this work on a Unix platform?
It does:
irb(main):004:0> File.expand_path(“~grzegorz”)
=> “/home/grzegorz”
I wonder whether this could/should be fixed.
I guess, it would not be a fix but an additional feature. The “~”
Well, I would simply like file names beginning with “~” to expand on
Windoze as any other file, that is, have the containing directory
prepended, instead of the string being returned as is. This current
behaviour seems broken to me.
expansion on Unix systems is a shell feature and no Unix built in
functionality.
Sorry, I was imprecise.
Cheers,
Grzegorz
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp
Any views or personal opinions expressed within this email may not be those of Talis Information Ltd.
The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.
“J.Hawkesworth” J.Hawkesworth@talis.com wrote in message news:8AD592BF2F0DD34E896E6283E53E8528DAAEF7@cally.talis.com…
I think I didn’t make myself sufficiently clear. On Unix, we get the
following, sensible behaviour:
irb(main):004:0> File.expand_path("~grzegorz")
=> “/home/grzegorz”
Indeed, “~someuser” expands as expected to the home directory of user
"someuser". If “someuser” does not exist. an error is signalled,
which again is reasonable, although the side-effect is that one cannot
give to File.expand_path file names that really start with “~”
(which on Unix is not a big deal, since such files are uncommon).
On Windoze, where the “~” convention is not used, in my opinion file
names starting with “~” should not be treated specially. When
current directory is “C:/”, I would expect
File.expand_path("~$foobar")
to return “C:/~$foobar”, just like
File.expand_path(“foobar”)
returns “C:/foobar”
An alternative would be to signal an error, but silently returning
"~$foobar" doesn’t make much sense. There is no reason on Windoze to
use the Unix convention and treat file names starting with “~” any
different that other files. What makes worse is the fact that many
temp files created by M$ Office applications use names starting with
"~$".
I hope this clarifies matters a bit.
Thougths?
···
–
Grzegorz
Hi,
On Windoze, where the “~” convention is not used, in my opinion file
names starting with “~” should not be treated specially. When
current directory is “C:/”, I would expect
File.expand_path(“~$foobar”)
to return “C:/~$foobar”, just like
File.expand_path(“foobar”)
returns “C:/foobar”
I don’t guess it is Windows specific issue.
An alternative would be to signal an error, but silently returning
“~$foobar” doesn’t make much sense. There is no reason on Windoze to
use the Unix convention and treat file names starting with “~” any
different that other files. What makes worse is the fact that many
temp files created by M$ Office applications use names starting with
“~$”.
When you are sure that it’s a real file name but not someone’s
home directory, you can avoid it by prepending “./”.
File.expand_path(path.sub(/\A(?=~)/, “./”))
···
At Wed, 18 Jun 2003 23:14:39 +0900, Grzegorz Chrupala wrote:
–
Nobu Nakada
nobu.nokada@softhome.net wrote in message news:200306211015.h5LAFckR030479@sharui.nakada.kanuma.tochigi.jp…
current directory is “C:/”, I would expect
File.expand_path(“~$foobar”)
to return “C:/~$foobar”, just like
File.expand_path(“foobar”)
returns “C:/foobar”
I don’t guess it is Windows specific issue.
On my Linux machine I get an error for File.expand_path(“~foo”) when
there is no user “foo”, on Windoze I get “~foo”.
When you are sure that it’s a real file name but not someone’s
home directory, you can avoid it by prepending “./”.
File.expand_path(path.sub(/\A(?=~)/, “./”))
That is useful, thanks!
Cheers,
···
–
Grzegorz