From: Robert Klemme Date: 2008-12-14T18:57:45+09:00 Subject: Re: Creating directory structures On 13.12.2008 18:09, Ch Ba wrote: >> Once you have an array of the source files, you should be able to >> create a list of the potential new files by replacing part of the >> source paths (using String#gsub). >> >> After that, enumerate your files, creating the directory (using >> File.dirname) and then creating the file. > > Excellent. That's what I'm looking for, I will follow up with my > results. There is another option that does not need gsub: use Dir[] with a directory wildcard and then just prepend source and target dir. Also, you can use FileUtils.mkdir_p which handles intermediate as well as existing directories gracefully. Cheers robert # ============= SPOILER BELOW ======================= require 'fileutils' Dir.chdir source_dir do Dir['**/*special*characters*'] end.each do |file| from = File.join(source_dir, file) if must_transform? from to = File.join(target_dir, file) FileUtils.mkdir_p(File.dirname(to)) transform(from, to) end end