From: "Einar Magnús Boson" Date: 2008-12-16T01:39:18+09:00 Subject: Re: Walk through directory structure, look at first file, rename dir in consequence. On 15.12.2008, at 16:17 , Aldric Giacomoni wrote: > This is pretty ugly and doesn't work.. Can't figure out why, but it > doesn't actually go through the main loop more than once. I'm a > little stuck here.. Any help is welcome :) > > def keep_iterating_until_not_directory() > Dir.glob('*') do |filename| > if File.directory?(filename) > Dir.chdir(filename) > keep_iterating_until_not_directory() > end > break > end > end > > def come_back_to_nycom > Dir.chdir("..") while Dir.pwd != "C:/Documents and Settings/username/ > My Documents/NYCOM" > end > > Dir.glob('*') do |filename| > if File.directory?(filename) > keep_iterating_until_not_directory() > end > puts Dir.pwd > image = DICOM::DObject.new(Dir.glob('*')[0], verbose=false, > library=lib) > come_back_to_nycom() > if image.get_raw("0008,1090") == "HDI 5000" > File.rename(filename, "HDI5000" + filename) > end > end > > something I wrote a while back that works: def getFilesInDirectory(dir) Dir[File.join(dir, "*")].collect do |f| if File.directory?(f) then getFilesInDirectory(f) else f end end.flatten end then you can use it like: getFilesInDirectory(Dir.pwd).each do |f| puts f end einarmagnus