logo       

Re: Getting the file name from a File::Stat object?: msg#00795

lang.ruby.general

Subject: Re: Getting the file name from a File::Stat object?

At Fri, 9 Aug 2002 22:46:32 +0900,
Lloyd Zusman wrote:

> Is there a way to get the file name from a File::Stat object?

Only way is to search files which have the inode number File::Stat#ino.
File::Stat represents status of an inode and an inode may be associated
many file names.

% mkdir foo
% cd foo
% touch a
% ln a b
% ln a c
% ls -i
2032361 a 2032361 b 2032361 c
% ruby -e 's = %w(a b c).map{|i| File.stat(i)}; p [s[0]==s[1], s[1]==s[2]]'
[true, true]
% touch d
% ls -i
2032361 a 2032361 b 2032361 c 2032364 d
% find . -inum 2032361
./a
./b
./c
% ruby -r find -e 'a = File.stat("a"); Find.find("."){|i| puts i if
File.stat(i).ino == a.ino}'
./c
./b
./a
%

But you might need to do Find.find("/") instead of Find.find(".").

-- Gotoken



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise