[ale] script or app to set all files to lower case

Brian Pitts brian at polibyte.com
Mon Aug 27 22:36:27 EDT 2007


James Taylor wrote:
> I need to convert a volume with several hundred thousand files with mixed case file names to all lower case.
> 
> Any suggestions for a quick, fast and easy utility to accomplish this?

I tried to do this in Ruby as an exercise, and it came out rather 
inelegant. Anyone on the list know the language and have a better approach?

# can't rename directories at the same time as files
# eg: find gives us /FOO/BAR but now it's at /foo/BAR. error!
# the order of directories is important for the same reason

require 'fileutils'
require 'find'
require 'ftools'
directories = Array.new
Find.find('/path/to/start/renaming/at') do |path|
   basename = File.basename(path)
   if basename.match('[A-Z]')
     if File.directory?(path)
       directories.unshift(path)
     else
       FileUtils.mv(path, path.gsub(basename,basename.downcase))
     end
   end
end
directories.each do |path|
   basename = File.basename(path)
   FileUtils.mv(path, path.gsub(basename,basename.downcase))
end



More information about the Ale mailing list