MATLAB Answers

gunzip subfolders at once

3 views (last 30 days)
Dave on 12 Oct 2021
Commented: Dave B on 12 Oct 2021
Hello, I have gz files stored in many sub-sub-folders; is there way I can gunzip all files at once into a single folder single_folder without looping over each sub-sub-folder?
The gz files are in subf6
To use gunzip I have to be in subf6
filenames = gunzip(????,'single_folder');
Is there a way to gunzip standing in subf1?

Accepted Answer

Dave B
Dave B on 12 Oct 2021
Edited: Dave B on 12 Oct 2021
You can pass wildcards to gunzip (note that the first example does exactly this):
fp = 'C:\Main\Data\subf1\subf2\subf3\subf4\subf5\subf6';
gunzip(fullfile(fp,'*.gz'),'single_folder'); % or maybe you want the output to be fullfile(fp, 'single_folder')?
Dave B
Dave B on 12 Oct 2021
Sounds like it works, sorry I misunderstood the question!
For future reference an alternative strategy is to build up the list of files and pass the list to gunzip

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!