How to extract contents of multiple tar files in a loop?

조회 수: 3 (최근 30일)
Susan
Susan 2021년 4월 1일
댓글: Susan 2021년 4월 1일
Hello Everyone,
I have multiple .tar.gz files that I'd like to extract contentes of them. For one file I use
path = 'C:\Users\data\example.tar.gz';
gunzip(path, 'example');
untar('example/example.tar','example');
However, I have many of these files (each one has a specific name) and I don't want to go through all of them one by one. I tried to use the following code in a for loop but no luck so far since these are not folders but .tar.gz files
D = 'C:\Users\data\';
S1 = dir(fullfile(D,'*'))
N1 = setdiff({S1([S1.isdir]).name},{'.','..'})
Any idea how I can do that?

채택된 답변

meghannmarie
meghannmarie 2021년 4월 1일
편집: meghannmarie 2021년 4월 1일
Do you mean something like this?
input_folder = 'C:\Users\data\';
file_struct = dir([input_folder '/**/*.tar.gz']);
file_names = {file_struct.name};
files = fullfile({file_struct.folder},file_names);
for f = 1:numel(files)
file = files{f};
untar(file);
end
  댓글 수: 4
meghannmarie
meghannmarie 2021년 4월 1일
Look at the help for untar:
untar(tarfilename,outputfolder)
so you would have this:
untar(file,destinationdirectory);
Susan
Susan 2021년 4월 1일
Thank you!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by