Message Boards Message Boards

0
|
6325 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Can read files in the compressed file directly?

I have a large number of compressed files (ZIP) stored in different directories. For some reason, I want to be able to read all the CSV files in the compressed files directly, but do not unzip it. Now, I can only read the file list in the compressed file. What should I do next?

dataList = FileNames["*.ZIP", "//Data//", 3];
data = Flatten[#, 1] &@Import[#, {"ZIP", "FileNames"}] & /@ dataList
POSTED BY: Tsai Ming-Chou
5 Replies
Posted 4 years ago

Hi Tsai,

What do you mean by

read all the CSV files in the compressed files directly, but do not unzip it

The zip file has to be unzipped to access its contents. Maybe this is what you are looking for?

data = Import[#, "*.csv"]& /@ datalist
POSTED BY: Rohit Namjoshi

This should be able to import the files in a zip archive:

zipFile = "testzip.zip";
data = Map[
  Import[zipFile, {"ZIP", #}] &,
  Import[zipFile, {"ZIP", "FileNames"}]
];
POSTED BY: Sjoerd Smit
Posted 4 years ago

You can use vim to list the content of the zip/rar/tar archive:

vim archive.zip

POSTED BY: Yasmin Hussain
POSTED BY: Tsai Ming-Chou

If you're having trouble reading in Chinese characters, I recommend fiddling about with the character encoding. I had a similar problem once that I solve by first setting:

$CharacterEncoding = "UTF8"

Give that a try before importing the files.

POSTED BY: Sjoerd Smit
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract