How to unzip multiple files(zipped) present in different subfolders

5 views (last 30 days)
I need help with unzipping files that are in different subfolders.
I have:
Folder 1 -> subfolder 1 -> zipped file1(NIFTI file of T1 weighted MRI image)
Folder 1 -> subfolder 2 -> zipped file2( NIFTI file of Mask image)
I would like to extract and move the "zipped file 1" and "zipped file 2" to a single folder.
Could you please provide an algorithm or code to carry out the same.

Answers (1)

Stephen23
Stephen23 on 23 Mar 2022
inp = 'absolute or relative path to Folder 1';
out = 'absolute or relative path to the output folder';
unzip(fullfile(inp,'nameOfSubfolder1','nameOfZippedFile1'),out)
unzip(fullfile(inp,'nameOfSubfolder2','nameOfZippedFile2'),out)
  2 Comments
LadyPhantom
LadyPhantom on 23 Mar 2022
There are around 1000 folders like this and I'd like to unzip all the similar way.
Stephen23
Stephen23 on 23 Mar 2022
Edited: Stephen23 on 23 Mar 2022
The use a loop:
For example:
S = dir(fullfile(inp,'**','*.ZIP'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
unzip(F,out)
end

Sign in to comment.

Categories

Find more on Medical Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!