From: mortee Date: 2007-09-28T22:54:44+09:00 Subject: Re: Recursing through directories Gabriel Dragffy wrote: > What I am trying to achieve is replace the slashes (/) in file/directory > names under a certain directory. So, for example, I want to recursively > rename offending files that are under /Volumes, but I don't want them > moved from their current directory... just renamed. What's the best way > to go about that? I guess you could do something like Dir['startdir/**/'].each { |dirname| Dir.new(dirname).each{ |file_basename| #manipulate file_basename => new_name oldpath = File.join(dirname, file_basename) newpath = File.join(dirname, new_name) File.move(oldpath, newpath) } } Note that the outer iterator will only yield you directory names, while the inner one will only yield file basenames inside those directories. So you can treat file names, even ones containing slashes on their own, and then combine the results with their respective directory names. mortee PS.: I could not figure out how to create a file with a / in its name in those few minutes so I could not test if this actually works if you have such files...