Wednesday, May 4, 2011

rename files with ruby

#!/usr/bin/env ruby
# This script renames files with white spaces with
# files with underscores in the current working directory.

require 'fileutils'
Dir.glob("*\ *").each do |original_file|
underscore_file = original_file.gsub(" ","_")
FileUtils.mv(original_file,underscore_file)
puts "Renamed: #{original_file} => #{underscore_file}"
end

No comments:

Post a Comment