Created
April 28, 2014 06:58
-
-
Save masaakif/11363721 to your computer and use it in GitHub Desktop.
サブディレクトリ以下の全ての*.txtをWorking Directoryに移動する。その際にディレクトリ名もつける
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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