From: Trick Nick Date: 2008-10-03T17:09:39+09:00 Subject: Re: Reg. Expressions with file directories Here is my solution to my problem, just thought I would share just incase someone else runs into a similar problem or is having similar issues. #first require the file utils, then take argument 1 or ARGV[0] and do a Dir.new ...to work on the given directory. Then get the entries(files) to test to see ...if they match the patterns given in the command line. require 'fileutils' givenDirectory = Dir.new("#{ARGV[0]}") dirEntries = givenDirectory.entries.sort i = 0 #Go through each file, or dirEntry and see if that file matches the pattern ...given. dirEntries.each do |file| if file.include?("#{ARGV[1]}") == true #store the new file's name by using the gsub in order to replace the given ...pattern(ARGV[1]) with the desired pattern from the commandline, or ARGV[2] newFileName = dirEntries[i].gsub("#{ARGV[1]}", "#{ARGV[2]}") #using the new file name copy the orginal file, with the new file name. FileUtils.cp("#{ARGV[0]}\/#{file}", "#{ARGV[0]}\/#{newFileName}") #rm the old file. print "File:#{file} \>\> NewFile:#{newFileName} \n" FileUtils.rm("#{ARGV[0]}\/#{file}") else print "#{file} DIDN'T CHANGE.\n" end i += 1 end -- Posted via http://www.ruby-forum.com/.