[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] script or app to set all files to lower case
- Subject: [ale] script or app to set all files to lower case
- From: brian at polibyte.com (Brian Pitts)
- Date: Mon, 27 Aug 2007 22:36:27 -0400
- In-reply-to: <[email protected]>
- References: <[email protected]>
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