From: Kirk Haines Date: 2005-07-26T08:31:14+09:00 Subject: Re: Script to walk a directory tree On Monday 25 July 2005 5:22 pm, Kyle Heon wrote: > Can anyone point me in the direction of how to walk a directory tree > recursively? > > I'm not having much luck finding code samples via Google. def file_search(dirpath, file_regex) r = [] Dir.foreach(dirpath) do |filename| next if filename == '.' or filename == '..' fullname = "#{dirpath}/#{filename}" if FileTest.directory? fullname r.concat(file_search(fullname)) elsif file_regex.match(filename) r.push fullname end end r end That's quick and dirty, but should give you a starting place to develop what you want. Pass into file_search a starting path (with a trailing '/'), and a regex that will match what you are looking for. You'll get back and array with everything that was found to match. Kirk Haines