I have a "ZIP" file that contains directories.

Import["arch.zip", "FileNames"]
(* {"subdir\\test.txt"} *)

However, Import errors that it cannot find the file in the subdirectory.

Import["arch.zip", {"subdir\\test.txt", "CSV"}]

Import::noelem: The Import element "subdir\test.txt" is not present when importing as ZIP. >>

However, if I add a file at the root of the zip

Import["arch.zip", "FileNames"]
(* {"subdir\\test.txt", "test2.txt"} *)

The root file imports it without issue

Import["arch.zip", {"test2.txt", "CSV"}]
(* {{1, 2, 3}, {4, 5, 6}} *)

How do I import files in subdirectories of zip files? I rather not import the entire zip as some of the files are very large and I don't need them.

I have not included a zip as I know people are squeamish about downloads.

May be a bug: Can anyone confirm 10.4.1 Win 7 Ent SP1

  • $\begingroup$ i just tried this and what you tried works fine. Maybe a version/system issue. (10.1/windows here) $\endgroup$ – george2079 Jun 10 '16 at 14:45
  • 1
    $\begingroup$ note for test purpose you can create such a zip like this: Export["testzip.zip",{"root.dat" -> {1}, "sub\\test.dat" -> {42}}] then Import["testzip.zip", #] & /@ Import["testzip.zip"] -> {{{1}}, {{42}}} $\endgroup$ – george2079 Jun 10 '16 at 14:53
  • 2
    $\begingroup$ Have you see ExtractArchive? $\endgroup$ – yode Jun 11 '16 at 1:36
  • 1
    $\begingroup$ Yup.It deserve to hunt. :) $\endgroup$ – yode Jun 11 '16 at 2:37
  • 2
    $\begingroup$ @yode This solved the problem. I was able to extract and access the file. I am sending a note to WRI that there is no intuitive way to find ExtractArchive. I think it may be a documentation link bug. $\endgroup$ – Edmund Jun 15 '16 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.