On Sat, Dec 22, 2001 at 08:00:08AM +0900, Bashar A. Asad wrote:
> am trying to write a script that will read in all the file names in dir X
> and convert the upper case letters to lower case. How can do such thing in 
> ruby?

Blatant ripoff of rename.pl:

#!/usr/bin/env ruby

def usage
    puts "#{ARGV[0]} f.expr [filenames]"
    exit 64
end

op = ARGV.shift or usage
files = !ARGV.empty? ? ARGV : STDIN.readlines.collect {|l| l.chomp}

files.each do |f|
    was = f
    begin
	eval "f = #{op}"
    rescue NameError => x
	puts "error: " + x.message
	exit 1
    end
    begin
	File.rename(was, f) unless was == f
    rescue => x
	puts "rename #{was} to #{f}: " + x.message
    end
end

Now do

	rename 'f.downcase' *

Anybody feel like improving on this? I don't like having to use the ``f''
variable...

-- 
Jos Backus                 _/  _/_/_/        Santa Clara, CA
                          _/  _/   _/
                         _/  _/_/_/             
                    _/  _/  _/    _/
josb / cncdsl.com     _/_/   _/_/_/            use Std::Disclaimer;