3
$\begingroup$

Suppose I have a zip archive file with many files in it. I can get a list of the files in the archive with:

Import["zipfile.zip"]

I can get data out of one of the files inside the archive with:

Import["zipfile.zip","somefile.txt"]

I can get the date the zip file was created with

FileDate["zipfile.zip"]

But I can't figure out how to get the dates of the files inside the zip file.

$\endgroup$
1
  • 4
    $\begingroup$ I can verify there is no way to do this currently without extracting the file first. This is a good suggestion, we'll look into this for future versions. $\endgroup$ Apr 4, 2019 at 2:34

1 Answer 1

4
$\begingroup$

I know you are probably looking for a pure Mathematica solution - looks like it's not supported by Mathematica (yet). However, don't forget that you can run any external program and analyze its output in Mathematica, so e.g. on macOS I can use unzip, which provides data in the following format:

17:06 /tmp $ unzip -l archive.zip 
Archive:  archive.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  04-03-2019 17:06   a.txt
        0  04-03-2019 17:06   b.txt
        0  04-03-2019 17:06   c.txt
---------                     -------
        0                     3 files

17:07 /tmp $ 

and therefore I can write this Mathematica function to do date processing for me:

zipDates[filename_] := 
 Interpreter["Date"]@
  StringSplit[
    StringSplit[
      RunProcess[{"unzip", "-l", filename}, "StandardOutput"], 
      "\n"][[4 ;; -3]],
    " "][[All, 3]]

result

$\endgroup$
1
  • $\begingroup$ Thanks for the reminder. Using an external function is a great idea. I'm using windows so I'll give this a try with 7-Zip. $\endgroup$ Apr 9, 2019 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.