First I thought of capturing the output of a find and using a text editor search-and-replace create a whole number of mv old_file new_file_without_spaces commands that could all be run. But then I would have to work with some editor's search-and-replace syntax.
Then I thought of writing a shell script. I started to think about find . -e ... but realized I always get confused about the -e syntax and using sed or awk.
Suddenly I realized I could do this with Ruby. About 10 minutes later I had this simple 3 line script, ran it and was done.
Dir[File.expand_path("#{~/file_with_spaces}/*")].uniq.sort.each do |file|
system "mv '#{file}' '#{file.gsub(' ', '_')}'"
end
Ruby is my new shell scripting language and I don't think I'm ever writing a bash shell script again!
0 comments:
Post a Comment