Zip files preserving timestamps

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs