# Zip Timestamp Extraction Help.....

**URL:** <https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966>\
**Category:** rubyonrails-talk\
**Created:** [October 10, 2010, 5:54pm UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966 "2010-10-10T17:54:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pete6](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@Pete6](https://discuss.rubyonrails.org/u/Pete6)\
**Post date:** [October 10, 2010, 5:54pm UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966/1 "2010-10-10T17:54:19Z")

</div>

Hi,

I am trying to validate uploads on an application where the uploaded file is a zipped archive, and I want some validation to include acceptable datestamps within the zipfile,

When I open a zip, with invalid datestamp, I receive the console output:

'Invalid date/time in zip entry'

Which is great, but I want to be able to extract this information and use it to reject the upload, but I can't seem to find a method which will allow me to extract this information from the zip.

Does anybody know of a method I can use which will return the date/ time stamp of the zip file, or return the Rescue statement above if it is invalid?

Thank you

Pete

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [October 10, 2010, 7:08pm UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966/2 "2010-10-10T19:08:22Z")

</div>

Install the rubyzip gem.

---

<div class="post-metadata">

**Author:** ![Pete6](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@Pete6](https://discuss.rubyonrails.org/u/Pete6)\
**Post date:** [October 11, 2010, 9:04am UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966/3 "2010-10-11T09:04:44Z")

</div>

Thanks,

rubyzip gem installed,

but I am still having the same problems - I am trying to use the methods (mtime etc) to access the timestamp information that is initially being returned as the rescue statement 'Invalid date/time in zip entry'

All I need to do is be able to access this 'invalid date/time' entry, but none of the 'time' methods seem to return this.

This message is only shown upon opening the zip file - is there a time method I can use on the zip itself, rather than on the contents which might show me the invalid timestamp?

Thanks again

Pete

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [October 11, 2010, 9:37pm UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966/4 "2010-10-11T21:37:31Z")

</div>

> but I am still having the same problems - I am trying to use the methods (mtime etc) to access the timestamp information that is initially being returned as the rescue statement 'Invalid date/time in zip entry'

What exactly is it that's returning that statement?

> All I need to do is be able to access this 'invalid date/time' entry, but none of the 'time' methods seem to return this.

I'm sure they don't. If, as I suspect, you're getting that message when you use 'unzip' from the command line, that message is coming from that specific program.

I would imagine you'll have to write your own method to examine the timestamps of the files in the zip and decide whether they meet your criteria for "invalid".

FWIW,

---

<div class="post-metadata">

**Author:** ![Pete6](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@Pete6](https://discuss.rubyonrails.org/u/Pete6)\
**Post date:** [October 13, 2010, 2:49pm UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966/5 "2010-10-13T14:49:41Z")

</div>

The line of output is acutally in the rubyzip.rb file itself, line 584

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [January 12, 2012, 9:32pm UTC](https://discuss.rubyonrails.org/t/zip-timestamp-extraction-help/54966/6 "2012-01-12T21:32:51Z")

</div>

I had the same problem; in my case it arose from treating the file reference returned from Zip::ZipFile.each{} as a string (like Dir.each{}) instead of whatever it actually is. Add ".name" where you need the file name. This code gave the error:

&nbsp;&nbsp;Zip::ZipFile.open(file) { |zip\_file| &nbsp;&nbsp;&nbsp;&nbsp;zip\_file.each { |f| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myLogger("Inspecting file #{f}") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next unless f.file? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

...and this worked:

&nbsp;&nbsp;Zip::ZipFile.open(file) { |zip\_file| &nbsp;&nbsp;&nbsp;&nbsp;zip\_file.each { |f| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myLogger("Inspecting file #{f.name}") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next unless f.file? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...

Cheers,

BillR
