stamping my own timestamp

P

Peter Bailey

Is there a way to "touch" a file with a time stamp of my own choosing,
in other words, not the "now" time? I've got a bunch of files that have
been inadvertently "touched" time-wise, and I need them to have truer
time stamps, from a month or so ago.

Thanks,
Peter
 
P

Peter Bailey

Robert said:
http://www.ruby-doc.org/core/classes/FileUtils.html#M004385

e.g. FileUtils.touch("foo", :mtime => Time.now)

robert

Thanks. But, this is what I get when I try that. Doesn't the "Time.now"
give it the time of right now?

irb(main):003:0> FileUtils.touch(file, :mtime => Time.now)
ArgumentError: no such option: mtime
from c:/ruby/lib/ruby/1.8/FileUtils.rb:1424:in
`fu_check_options'
from c:/ruby/lib/ruby/1.8/FileUtils.rb:1009:in `touch'
from (irb):3
 
R

Robert Klemme

2007/7/16 said:
Thanks. But, this is what I get when I try that. Doesn't the "Time.now"
give it the time of right now?

irb(main):003:0> FileUtils.touch(file, :mtime => Time.now)
ArgumentError: no such option: mtime
from c:/ruby/lib/ruby/1.8/FileUtils.rb:1424:in
`fu_check_options'
from c:/ruby/lib/ruby/1.8/FileUtils.rb:1009:in `touch'
from (irb):3

Works for me:

irb(main):003:0> FileUtils.touch "f", :mtime => Time.now
=> ["f"]
irb(main):004:0> RUBY_VERSION
=> "1.8.6"
irb(main):005:0> File.mtime "f"
=> Mon Jul 16 15:52:06 +0200 2007

Alternatively you can try to use File.utime().

Kind regards

robert
 
P

Peter Bailey

Robert said:
2007/7/16 said:
from (irb):3
Works for me:

irb(main):003:0> FileUtils.touch "f", :mtime => Time.now
=> ["f"]
irb(main):004:0> RUBY_VERSION
=> "1.8.6"
irb(main):005:0> File.mtime "f"
=> Mon Jul 16 15:52:06 +0200 2007

Alternatively you can try to use File.utime().

Kind regards

robert

Thanks, Robert. That particular thing just doesn't work for me, but, I'm
intrigued by File.utime. I read about it a bit and I think it might do
the trick. Thanks a lot!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,311
Members
47,986
Latest member
ColbyG935

Latest Threads

Top