From: Intransition on 9 Mar 2010 13:08 I probably should know the answers to these, but it's never come up before. How to check if a symbolic link exists and already points to where you expect it to point? And how to check for dead symbolic links? Thanks.
From: Gary Wright on 9 Mar 2010 13:28 On Mar 9, 2010, at 1:08 PM, Intransition wrote: > I probably should know the answers to these, but it's never come up > before. > > How to check if a symbolic link exists and already points to where you > expect it to point? > > And how to check for dead symbolic links? Try playing around with the following: def info(path) lstat = File::lstat(path) rescue nil return "not found" unless lstat if lstat.symlink? target = File::readlink(path) stat = File::stat(path) rescue nil if stat "symlink to #{target}" else "dead symlink to #{target}" end else "not a symlink" end end ARGV.each { |f| puts "#{f}: #{info(f)}" }
|
Pages: 1 Prev: Getting Constructor Not Found (Ruby Java Bridge, RJB) Next: Compile/Close Ruby Code |