# FileUtils changes date of file

**URL:** <https://www.ruby-forum.com/t/fileutils-changes-date-of-file/104108>\
**Category:** Ruby\
**Created:** [May 14, 2007, 12:21pm UTC](https://www.ruby-forum.com/t/fileutils-changes-date-of-file/104108 "2007-05-14T12:21:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 14, 2007, 12:21pm UTC](https://www.ruby-forum.com/t/fileutils-changes-date-of-file/104108/1 "2007-05-14T12:21:46Z")

</div>

Hi,

I use ruby under WinXP and discovered the following issue.

When I copy a file with the following code

require ‘fileutils’  
FileUtils.cp("file1’,‘file2’)

the date of the destination file won’t match the date of the source  
file.  
It’s set to the time of the copy process. But it should be the date of  
the original file.  
How can I get this working correct?

Thanks  
Peter

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 14, 2007, 12:35pm UTC](https://www.ruby-forum.com/t/fileutils-changes-date-of-file/104108/2 "2007-05-14T12:35:48Z")

</div>

On 14.05.2007 12:16, removed\_email\_address@domain.invalid wrote:

> the original file.  
> How can I get this working correct?

First of all: this is expected behavior and is similar to what cp does.  
So this is in no way “incorrect” even though your expectation was  
different because Windows Explorer handles this differently.

To retain meta data do

FileUtils.cp("file1’,‘file2’, :preserve =\> true)

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 14, 2007, 1:07pm UTC](https://www.ruby-forum.com/t/fileutils-changes-date-of-file/104108/3 "2007-05-14T13:07:54Z")

</div>

On May 14, 2007, at 7:35 PM, Robert K. wrote:

> > How can I get this working correct?  
> > Kind regards
> 
> robert

Consider it a difference between copying a file and cloning. Copying  
would be the same as what you normally do with a mouse in the GUI.  
Cloning would be more like what backup/restore software does with file.  
Sure, we can argue that the two things are the same in everyday  
language, but it’s all built on the logic of whoever first built the  
thing, and we can never really assume much of anything about what  
some computer term means.
