Forum: Ruby Ruby, find path of a directory

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
067fb05dff0f6a2e9ec5782c3c146109?d=identicon&s=25 shaik s. (shaik_s)
on 2013-10-29 14:17
Is it possible to find/get the complete path of a directory by
specifying the
directory name as which drive it is in? For example

I've a directory on drive as D:\abc\efg\screenshots\

I want to find the complete path of the directory screenshots, not sure
on which drive it exists, may be C: or D: or E: but the parent folder
starts with abc\efg\screenshots\

Apreciate response

AR (aka AleiPhoenix) (Guest)
on 2013-10-29 15:17
(Received via mailing list)
On Tue, Oct 29, 2013 at 9:17 PM, shaik s. <> wrote:

> Apreciate response
> Thx,
> #M

assuming working directory is /tmp .

File.expand_path "whatever" #  => "/tmp/whatever"
File.absolute_path "whatever" #  => "/tmp/whatever"

$ ln -s /tmp/whatever /tmp/1 # make a symlink

File.expand_path "1" #  => "/tmp/1"
File.absolute_path "1" #  => "/tmp/1"
File.realpath "1" => "/tmp/whatever"

I didn't try this on windows platform, If you don't want the drive, you
could try

'D:\hello\world'.gsub(/^\w+:\\/, '')

correct my if directory separator char for ruby on windows is '/' .

Silence is golden.

twitter: @AccelReality
wikipedia: AleiPhoenix
This topic is locked and can not be replied to.