Forum: Ruby Help on copy file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2009-04-28 09:21
Hi..
is it possible to copy a file which is newer than the existing one.
how can i check that?
Any Ideas.

Thanks
9dec3df8319c613f6f4f14a27da0fdb4?d=identicon&s=25 Kyle Schmitt (Guest)
on 2009-04-29 17:02
(Received via mailing list)
Go read about the file class in ruby.  FileUtils may give you a few
more options, but for this you don't actually need it.

Use the stat method of an open file to get information about when it
was created, modified accessed, etc.

Here, I am getting the data on my file named "HP Laptop" where I've
got the chat log from the 6th time I had to send the damned thing back
to HP.

file=File.open("HP Laptop")
file.stat
=><File::Stat dev=0x802, ino=2680032, mode=0100644, nlink=1, uid=1000,
gid=1000, rdev=0x0, size=123838, blksize=4096, blocks=256, atime=Tue
Apr 28 11:18:19 -0500 2009, mtime=Fri Apr 24 13:49:05 -0500 2009,
ctime=Fri Apr 24 13:49:05 -0500 2009>
file.stat.ctime
=>Fri Apr 24 13:49:05 -0500 2009
file.stat.mtime
=>Fri Apr 24 13:49:05 -0500 2009
file.stat.atime
=> Tue Apr 28 11:18:19 -0500 2009

You can see I created the file on April 24th, and haven't modified it
since.  You also see it was last accessed on April 28th.

Now go dig into the File class, it has a move command, a copy command,
and all sorts of goodies that will help you do this for yourself, and
learn along the way.

--Kyle
9dec3df8319c613f6f4f14a27da0fdb4?d=identicon&s=25 Kyle Schmitt (Guest)
on 2009-04-29 17:03
(Received via mailing list)
Right, one more thing :)
ctime  is create time
mtime is modify time
atime is access time
This topic is locked and can not be replied to.