Created
May 21, 2009 12:53
-
-
Save pokutuna/115443 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class File | |
def self.actual_path(file = nil) | |
file = __FILE__ if file == nil | |
file = File.expand_path(file) | |
if File.ftype(file) == 'link' then | |
actpath = File.readlink(file) | |
file = File.actual_path(actpath) | |
end | |
return file | |
end | |
end | |
if $0 == __FILE__ then | |
p __FILE__ | |
p File.expand_path(__FILE__) | |
p File.actual_path(__FILE__) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd ~/ | |
$ mkdir slinktest | |
$ cd slinktest | |
$ mkdir hoge | |
$ cd hoge | |
$ cp ~/filepath.rb ./ | |
$ cd .. | |
$ ln -s hoge/filepath.rb ./filepath_slink.rb | |
$ ls -l | |
合計 4 | |
lrwxrwxrwx 1 pokutuna pokutuna 16 2009-05-21 21:46 filepath_slink.rb -> hoge/filepath.rb | |
drwxr-xr-x 2 pokutuna pokutuna 4096 2009-05-21 21:43 hoge | |
$ ruby filepath_slink.rb | |
"filepath_slink.rb" | |
"/home/pokutuna/slinktest/filepath_slink.rb" | |
"/home/pokutuna/slinktest/hoge/filepath.rb" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment