Skip to content

Instantly share code, notes, and snippets.

@masaakif
Created April 28, 2014 06:58
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 masaakif/11363721 to your computer and use it in GitHub Desktop.
Save masaakif/11363721 to your computer and use it in GitHub Desktop.
サブディレクトリ以下の全ての*.txtをWorking Directoryに移動する。その際にディレクトリ名もつける
Dir.glob("**/*.txt") do |f|
origname = f
newname = File.basename(f)
dirn = File.dirname(f)
dirn = dirn.gsub!("/","_")
unless dirn.nil?
newname = dirn + newname
end
puts "#{origname} -> #{newname}"
File.rename(origname, newname)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment