# How to Import file from subdirectory of ZIP file?

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.

• 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}}} – george2079 Jun 10 '16 at 14:53
• Have you see ExtractArchive? – yode Jun 11 '16 at 1:36
• @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. – Edmund Jun 15 '16 at 21:00