From: Dave Thomas Date: 2002-04-01T12:16:41+09:00 Subject: Re: Recursing thru directories? Brad Cox writes: > Could someone please provide the ruby idiom for visiting each file in > a directory and its subdirectories? I'm missing something, obvious no > doubt. Brad: There's File.find: require "find" Find.find("/etc/passwd", "/var/spool/lp1", ".") do |f| Find.prune if f == "." puts f end produces: /etc/passwd /var/spool/lp1 /var/spool/lp1/status /var/spool/lp1/lock /var/spool/lp1/.seq The Find module supports the top-down traversal of a set of file paths. class methods: find ref.find( [ aName ]* ) {| aFileName | block } Calls the associated block with the name of every file and directory listed as arguments, then recursively on their subdirectories, and so on. prune ref.prune Skips the current file or directory, restarting the loop with the next entry. If the current file is a directory, that directory will not be recursively entered. Meaningful only within the block associated with Find::find. Cheers Dave