Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Archive::Zip returns incorrrect 'file last modified date'

by jeanluca (Deacon)
on Dec 10, 2009 at 18:15 UTC ( [id://812263]=perlquestion: print w/replies, xml ) Need Help??

jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I need the last modified time from the files in a zipped archive. Here is my test code
#! /usr/bin/perl -l use strict ; use warnings ; use Data::Dumper ; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); # Read a Zip file my $zip = Archive::Zip->new(); unless ( $zip->read( 'out.zip' ) == AZ_OK ) { die 'read error'; } my @members = $zip->members(); foreach my $element(@members) { printf("%d %s %s\n", $element->lastModFileDateTime(), scalar(localtime($element->lastModFileDateTime())), $element->fileName() ); }
Output:
983734011 Sun Mar 4 20:26:51 2001 dir3/ 983734011 Sun Mar 4 20:26:51 2001 dir3/file3
However, here is the output from unzip
$> unzip -l out.zip Archive: out.zip Length Date Time Name -------- ---- ---- ---- 0 05-02-09 18:55 dir3/ 0 05-02-09 18:55 dir3/file3 -------- ------- 0 2 files
Note that the dates do not match. I guess there is a logical explanation for this, any suggestion ?

Cheers
LuCa

UPDATE: thnx derby, lastModTime solved it!!

Replies are listed 'Best First'.
Re: Archive::Zip returns incorrrect 'file last modified date'
by derby (Abbot) on Dec 10, 2009 at 18:58 UTC

    Looking at the docs for Archive::Zip, lastModFileDateTime returns a date time stamp in MS-DOS format while lastModTime returns the epoch seconds. You either should just print lastModFileDateTime *or* send lastModTime to the localtime function.

    -derby

    Update: I do not not enough about MS-DOS date time stamps ... just printing it will not work but the lastModTime method is probably what you're after.

    Update 2: Doh! MS-DOS epoch start is Jan 1, 1980. I should have figured that out from the dates in the OP.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://812263]
Approved by broomduster
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found