Create a new file name by appending timestamp to original

i want a new file name from existing file name but with attaching time
stamp but gives error invalid argument type please tell simple way for
doing this

2008/5/7 Sunny B. [email protected]:

i want a new file name from existing file name but with attaching time
stamp but gives error invalid argument type please tell simple way for
doing this

If you do not tell us what you did and what error you saw we cannot
help you. Did you look at
http://www.ruby-doc.org/core/classes/Time.html#M000297 ?

Kind regards

robert

Robert K. wrote:

2008/5/7 Sunny B. [email protected]:

i want a new file name from existing file name but with attaching time
stamp but gives error invalid argument type please tell simple way for
doing this

If you do not tell us what you did and what error you saw we cannot
help you. Did you look at
http://www.ruby-doc.org/core/classes/Time.html#M000297 ?

Kind regards

robert

i want attaches a timestamps to file for this i doing Time.now_filename
but it gives error because time has a space sum it so i need some
another mechanism using which i generate timestamps and attached to
timestamps.

On 07.05.2008 11:08, Sunny B. wrote:

but it gives error because time has a space sum it so i need some
another mechanism using which i generate timestamps and attached to
timestamps.

Not sure what you are really doing, I get

$ ruby -e ‘Time.now_filename’
-e:1: undefined method `now_filename’ for Time:Class (NoMethodError)

But Pena’s solution is probably what you want. Here’s another approach:

file_name = “base_name-#{Time.now.strftime(’%Y%m%d-%H%M%S’)}”

Kind regards

robert

From: Sunny B. [mailto:[email protected]]

i want attaches a timestamps to file for this i doing

Time.now_filename

but it gives error because time has a space sum it so i need some

another mechanism using which i generate timestamps and attached to

timestamps.

pardon me if i do not get you right here, but do you want something like
this, eg?

system “dir *testing.rb”
01/31/2003 05:55 PM 4 testing.rb
1 File(s) 4 bytes
#=> true

require ‘fileutils’
#=> true

FileUtils.mv f, [Time.now.strftime("%Y-%m-%d-%H%M%S"),f].join("_")
#=> 0

system “dir *testing.rb”
01/31/2003 05:55 PM 4 2008-05-07-173139_testing.rb
1 File(s) 4 bytes
#=> true

kind regards,
-botp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs