Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Created July 5, 2012 09:54
Show Gist options
  • Select an option

  • Save jgwhite/3052699 to your computer and use it in GitHub Desktop.

Select an option

Save jgwhite/3052699 to your computer and use it in GitHub Desktop.
files = Dir['*/*']
files.each do |old_path|
old_dir = old_path.split('/').first
next if old_dir.length < 12
new_path = old_path.sub(%r[(.{3})(.{9})/(.{12})], '\1/\2\3')
`mkdir -p #{$1}`
`mv #{old_path} #{new_path}`
if Dir[old_dir + '/*'].empty?
`rm -r #{old_dir}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment