# Zip files preserving timestamps

**URL:** <https://www.ruby-forum.com/t/zip-files-preserving-timestamps/208291>\
**Category:** Ruby\
**Created:** [June 14, 2011, 10:42am UTC](https://www.ruby-forum.com/t/zip-files-preserving-timestamps/208291 "2011-06-14T10:42:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 14, 2011, 10:42am UTC](https://www.ruby-forum.com/t/zip-files-preserving-timestamps/208291/1 "2011-06-14T10:42:29Z")

</div>

Hi,

I’m using Ruby 1.8.7 and the gem ‘zip’ (2.0.2) to zip up an array of  
filenames found in a directory:

Zip::ZipFile.open(dir + ‘.zip’, Zip::ZipFile::CREATE) do |zipfile|  
files.each do |f|  
zipfile.add(f, File.join(dir, f))  
end  
end

- which works fine.

However, the zip archive holds files with timestamps of the time the zip  
file was created, rather than preserving the original timestamps of the  
files, which is what I am after.

I’ve had a look at the gem docs but can’t see anything obvious about  
setting/preserving timestamps.

Can anyone offer assistance? Is rubyzip a better option (although I’m  
sometimes deploying on 1.9 so prefer zip)

Thanks.

Mike.
