Forum: Ruby Ruby, find path of a directory

462c96e85144024df16705e088c0d638?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

Thx,
#M
Ce1e13bbf946c92e2abf740f8909bafa?d=identicon&s=25 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. <lists@ruby-forum.com> 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
blog: weblog.areverie.org
wiki: wiki.areverie.org
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.