How to access .csv files in a .tar.gz file?

12 ビュー (過去 30 日間)
Susan
Susan 2020 年 7 月 8 日
コメント済み: Susan 2020 年 7 月 17 日
Greeting!
I have a bunch of *.tar.gz files, say 100 (example1-example 100). In each of them I have more than 1000 .csv file that I would like to extract data from these .csv files.
I am using following code to access the .csv files.
url = 'C:\Users\....\Test\example1.tar.gz';
files = gunzip(url, 'example1')
what I get is
files = 1*1 cell array
{'example1\example1.tar'}
However it doesn't make any "example1.tar" in the "C:\Users\....\Test\" folder. Then I'm using the following line to get the . cvs files
filenames = untar('example1/example.tar','example1')
and I get
filenames = 1*953 cell array
{example1\example_1\} {example1\example_1\config1\} {example1\example_1\config1\imag.csv} {example1\example_1\config1\real.csv}.....
{example1\example_1\config50\} {example1\example_1\config50\imag.csv} {example1\example_1\config50\real.csv} ......
I would like to have access the data on imag.csv and real.csv for all configs. How should I do that?
Should I use something like
load(fullfile('..', 'example1', 'example_1', 'config1', 'imag.csv'))
Thank you for any help you can provide, I'm really stuck on this.
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 7 月 16 日
I do not know if the following will work for .gz but you could try it: https://www.mathworks.com/matlabcentral/fileexchange/77257-zipfile
Susan
Susan 2020 年 7 月 17 日
Thanks for your feedback. I've checked these links out but couldn't help to solve my problem. Thanks though!

サインインしてコメントする。

回答 (1 件)

Aditya Patil
Aditya Patil 2020 年 7 月 16 日
You can call a function recursively on the folder, and process the files which match your requirement. See https://www.mathworks.com/matlabcentral/answers/92761-how-can-i-recursively-process-files-in-subdirectories-using-matlab for detailed explanation.
  1 件のコメント
Susan
Susan 2020 年 7 月 17 日
Thanks! I will check that out.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by