From: Jacob Davis Date: 2010-05-11T23:27:11+09:00 Subject: Re: Problem renaming files Jes炭s Gabriel y Gal叩n wrote: > On Tue, May 11, 2010 at 5:10 AM, Jacob Davis wrote: >> I want to rename mulitple files, removing the build number, and >> Below is the code.. I run the file as: >> (Errno::ENOENT) >> # Have user input build number to be removed >> >> puts "done!" > > There are two problems here. The first one is that > file_names[build_number] = version will return the right hand side > expression, not the new value of the string, so you will be passing a > "5" to the rename method, not "engine.5". The second is that by > calling []= on file_names you are changing the object referenced by > file_names, not making a new one, so you are passing "engine.5" as the > first argument to rename. Try this instead: > > > # Rename file replacing build number with version number > new_name = file_names.dup > new_name[build_number] = version_number > File.rename(file_names, new_name) > > Also, when you change things to receive multiple file names as > arguments to your script, you should probably change this line: > > file_names = ARGV.dup.to_s > > because that will join all the file names into a single string, which > is not what you want, I think. > > Jesus. Awesome! Yeap that worked! I see where I was making the mistakes last night. I guess its good to step away from it for a bit everyonce in a while. So, I should remove the .to_s so that it will populate the multiple names into an array correct? Thanks!!!! Jacob -- Posted via http://www.ruby-forum.com/.