Loop naming for variable

Hi all,

   I want to rename the file name if the file is exist.

   If filexample.txt exist, the original filexample.txt will be

   renamed to filexample_1.txt.

   And I set a variable mapping to one download path

   --> "local_file_1 = local_path +'/'+ filename + '_1'".

   How to re-write below code by for-loop or while?

   local_path ="/home/usr"

   local_file_1 = local_path +'/'+ filename + '_1'
   local_file_2 = local_path +'/'+ filename + '_2'
   local_file_3 = local_path +'/'+ filename + '_3'
   ....
   local_file_n = local_path +'/'+ filename + '_n'

   Thanks,

Regards,

···

--
Posted via http://www.ruby-forum.com/.

Hi,

I don't quite understand what you mean. Do you have a list of file names
and want to rename every existing file with that name?

Also I don't see the purpose of the variables. Why don't you do the
"directory translation" when it's needed rather than cluttering the
program with variables? By the way: That's what arrays or hashes are
for.

···

--
Posted via http://www.ruby-forum.com/.