Skip to content

Instantly share code, notes, and snippets.

@aont
Last active December 22, 2015 04:58
Show Gist options
  • Select an option

  • Save aont/6420613 to your computer and use it in GitHub Desktop.

Select an option

Save aont/6420613 to your computer and use it in GitHub Desktop.
flatten directory
#!/usr/bin/ruby
require 'fileutils'
def flatten(path)
Dir::entries(path).each do |fn|
next if fn=="." || fn==".."
FileUtils::mv("#{path}/#{fn}", "#{path}__#{fn}")
end
FileUtils::rmdir(path)
end
ARGV.each do |argv|
flatten(argv.chomp("/"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment