Collapsing Folder Trees with Ruby
options={}
# ...
if not options[:types]
  options[:types] = ["mp3", "m4a"]
end


I would initialize options with the default values first, instead of checking whether the option is set afterwards. I.e.

options = {:types =&gt; ["mp3", "m4a"]}




options[:types].each{|ext| `find -iname '*.#{ext}' -exec mv {} ./ \\\;`}


This can be done with a glob. For this I'd first change options[:types] to be string (i.e. replace Array with String in the optparse code and use "mp3,m4a" instead of ["mp3", "m4a"] as the default. Then you can use Dir.glob with FileUtils.mv like this:

Dir.glob("**/*.{#{ ext }}") {|f| FileUtils.mv(f, ".")}





  I suspect that I could replace the find calls with native Ruby methods, but I can't see how without complicating it significantly.


For the first one see above. However the second one would indeed be more complicated to replace, so I'd just stick with the find call.




  I also suspect that there's a better way of writing FileUtils.cd("#{origin}/#{target}")


Yes, there is: cd optionally takes a block. When given a block, cd will cd into the given directory, execute the block, and then cd back. So you can get rid of origin and just do

FileUtils.cd(target) do
  ...
end




FileUtils.cd(origin)


Even without using the block version of cd the above line would be completely unnecessary. Changing the directory at the end of a script has no effect. Any cd performed in a process will never affect the parent process.