From: "Stephan Kämper" Date: 2004-09-26T01:45:08+09:00 Subject: Re: Directory search STEPHEN BECKER I V wrote: > I am writing a program to go in all the folders, then in to there folders.... > You might like to read http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/20172 and the answers to that one. What's done there is to add a walker method to class DIR - which as the name implies walks through the directory and uses a passed block to do something with the current path name. I currently have code like this class Dir def walk ( prefix = nil, &walker ) e = self.entries e.delete "." e.delete ".." e.collect!{ | x | File.join( prefix, x ) } if prefix if block_given? e.each { | x | if File.directory?( x ) Dir.new( x ).walk( x, &walker ) end yield x } end nil end end Dir.new( "E:/" ).walk( "E:/" ) { | p | puts p if p =~ /ruby/ } But note that this code won't work on XP if there are any directories of files which can only be read with administrator rights: You'll run into a 'permission denied (Errno::EACCES)'... I'll have to work on that. Happy rubying Stephan