This question already has an answer here:

I have a ZIP archive that does not have the .zip file extension. How can I import a file from this archive using Import and specifying a particular import format or element?

Test case:

x = 1;
Export["x.m", HoldComplete[x], "HeldExpressions"]
RenameFile["x.m.zip", "a.foo"]

Now I can

Import["a.foo", {"ZIP", "x.m"}]
(* 1 *)

But I want to import x.m as "HeldExpressions". How can I do this? I cannot figure out the syntax.

Doing this is useful because lots of file formats are based on zip, e.g. Java JAR files, Microsoft Office files, .paclet files, etc. Suppose I want to import an XML from a .docx or I want to import a PacletInfo.m as "HeldExpressions".

I know I can ExtractArchive first, import, and delete the extracted file. This question is about whether this is achievable with a single Import call.


marked as duplicate by Szabolcs, Community Dec 3 '16 at 11:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ let me guess what you are just trying :-). Have you tried Import["a.foo", {"ZIP", "x.m", "HeldExpressions"}], that seems to work for me... It even is kind of documented in the details section of Import (in the part "assume also compression formats...") $\endgroup$ – Albert Retey Dec 3 '16 at 10:22
  • $\begingroup$ @AlbertRetey Please post an answer ... I really couldn't find it $\endgroup$ – Szabolcs Dec 3 '16 at 10:35
  • 1
    $\begingroup$ Related, perhaps duplicate?: mathematica.stackexchange.com/q/2871/121 $\endgroup$ – Mr.Wizard Dec 3 '16 at 10:43

The following seems to work:

 Import["a.foo", {"ZIP", "x.m", "HeldExpressions"}]

the documentation is not really clear about it, but the explanation about compressed formats in the Details section of the Import documentation page can be read as if this should work.


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