# Help on copy file

**URL:** <https://www.ruby-forum.com/t/help-on-copy-file/166651>\
**Category:** Ruby\
**Created:** [April 28, 2009, 9:21am UTC](https://www.ruby-forum.com/t/help-on-copy-file/166651 "2009-04-28T09:21:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 28, 2009, 9:21am UTC](https://www.ruby-forum.com/t/help-on-copy-file/166651/1 "2009-04-28T09:21:20Z")

</div>

Hi…  
is it possible to copy a file which is newer than the existing one.  
how can i check that?  
Any Ideas.

Thanks

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 29, 2009, 5:02pm UTC](https://www.ruby-forum.com/t/help-on-copy-file/166651/2 "2009-04-29T17:02:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [April 29, 2009, 5:03pm UTC](https://www.ruby-forum.com/t/help-on-copy-file/166651/3 "2009-04-29T17:03:06Z")

</div>

Right, one more thing 🙂  
ctime is create time  
mtime is modify time  
atime is access time
