From: Jacob Davis Date: 2010-05-11T12:10:22+09:00 Subject: Problem renaming files Hi Everyone, Im new to ruby and am having a hard time with something Im working on. I want to write a script that takes file names as arguments, then uses gets to get two values, and then renames the files based on those values. example: I want to rename mulitple files, removing the build number, and replacing it with another number. engine.105 -> rename to engine.8 Anyways, so right now Im just working on doing this with one file at a time. I realize this could be done without a script, but I want to end up doing this with multiple files at once. My script is probably not the most efficient way either, but I'd just like to know what Im doing wrong with how Im doing it. Just so I can learn.. Below is the code.. I run the file as: ruby c.rb engine.105 I then enter the build number which is 105 Next I enter the version number I want to replace the build number with which is 5 The following is what I get: c.rb:14:in `rename': No such file or directory - engine.5 or 5 (Errno::ENOENT) from c.rb:14 ===================== #!/usr/bin/env ruby # Filename arguments file_names = ARGV.dup.to_s # Have user input build number to be removed puts "Please enter the build number you wish to be removed from the file" build_number = STDIN.gets.chomp.to_s # Have user input version number to be appended to file name puts "Please enter the version number you wish to be appended" version_number = STDIN.gets.chomp.to_s # Rename file replacing build number with version number File.rename(file_names, file_names[build_number]= version_number) puts "done!" Attachments: http://www.ruby-forum.com/attachment/4719/c.rb -- Posted via http://www.ruby-forum.com/.