How to follow symlinks to directories?

Find#find automatically follows symbolic links to real files but
not to directories. How can I perform a recursive traversal of
a directory tree including sym.links to directories?

Thanks,
P

···


^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^^~^~^~^~^
Peter B. Ensch peterbe@attbi.com
^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^^~^~^~^~^

The Unix command-line find has a ‘-follow’ option.

Under Ruby you could try something nefarious like:

require ‘find’
dirs = [“.”]
dirs.each do |dir|
Find.find(dir) do |f|
dirs.push File.readlink(f) if FileTest.symlink?(f) and FileTest.directory?(f)
puts f
end
end

I’m never particularly happy about modifying an array whilst iterating
through it :slight_smile:

The above code almost certanily won’t work for relative symbolic links, e.g.
e.g. foo/bar/src → …/baz/src

It would be nice if Find had a ‘follow’ method, like ‘prune’, which did the
Right Thing[TM]

Regards,

Brian.

···

On Sat, Apr 05, 2003 at 03:02:40PM +0900, Peter B. Ensch wrote:

Find#find automatically follows symbolic links to real files but
not to directories. How can I perform a recursive traversal of
a directory tree including sym.links to directories?