From: Gennady Date: 2003-03-26T06:14:44+09:00 Subject: Re: Recursive methods allowed in Ruby? For this particular case, it is much easier to use class Find (require "find", p. 450 of Pickaxe) to do directory traversing for you. It works similar to Unix 'find' command. Gennady. ----- Original Message ----- From: "Brian Candler" To: "ruby-talk ML" Sent: Tuesday, March 25, 2003 1:01 PM Subject: Re: Recursive methods allowed in Ruby? > On Wed, Mar 26, 2003 at 05:50:47AM +0900, Krishna Dole wrote: > > def list_dirs( inDir ) > > Dir.foreach( inDir ) {|x| > > print( x ) > > if File.ftype( x ) == "directory" > > list_dirs( x ) > > end > > } > > end > > > > ARGV.each{ |dirName| > > list_dirs(dirName) > > } > > Dir.foreach lists "." (current directory" and ".." (parent directory) which > is why you are getting infinite recursion. Try adding: > next if x == "." or x == ".." > > To make your program work you will also need to chdir() into each directory, > or else build up a pathname, so that directories within directories are > found. Something like this: > > path = inDir + "/" + x > if File.ftype( path ) == "directory" > list_dirs( path ) > end > > Regards, > > Brian. > >