Skip to content

Instantly share code, notes, and snippets.

@dsisnero
Created April 6, 2011 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsisnero/906649 to your computer and use it in GitHub Desktop.
Save dsisnero/906649 to your computer and use it in GitHub Desktop.
pathname stuff
require 'pathname'
require 'fileutils'
require 'set'
base = Pathname('/newdir/obsolete')
old_dirs = Set.new
Pathname.glob('dir/*/obsolete/*').each do |pn|
dir, file = pn.split
customer = dir.parent.basename
target_dir = base + customer
target_dir.directoy? or target_dir.mkdir
target = target_dir + file
FileUtils.mv pn, target
old_dirs << dir
end
old_dirs.each {|d| Dir.delete d}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment