Following is my code for unizipping a '.zip' file. However, I get a error when I use it for a compressed folder (.zip). Can you help me rectify the error? If not, can you also suggest some way to directly parse the zip folder name and access the dir?
1 view (last 30 days)
Show older comments
Mihir Gadkari
on 20 Jun 2016
Commented: Stephen23
on 21 Jun 2016
dt_opr = '05-29-2016';
output_folder = [mainpath datestr(dt_opr, 'yyyy-mm-dd') '\' ];
if exist([output_folder], 'dir') ~= 7
mkdir(output_folder);
end
zip_files = dir([mainpath '*RPT.00013070*' datestr(dt_opr, 'yyyymmdd') '*.zip']);
unzip(zip_files.name, output_folder);
0 Comments
Accepted Answer
Walter Roberson
on 20 Jun 2016
A) I suggest you re-write using fullfile()
B) You refer to zip_files.name but you constructed zip_files as a string. It looks to me as if at some point you had a dir() in there. But remember that if you dir() then you need to loop around the results, and remember that the .name fields does not include the directory, so you would normally need to fullfile() to reconstruct the complete path. Which is a problem if you are using wildcards on the directory because you would not know which directory you were in.
I think you might want to have a look at https://www.mathworks.com/matlabcentral/fileexchange/32226-recursive-directory-listing-enhanced-rdir
3 Comments
Stephen23
on 21 Jun 2016
@Mihir Gadkari: often it is better to use fullpath for every filepath:
str = datestr(dt_opr, 'yyyymmdd');
str = sprintf('*RPT.00013070*%s*.zip',str);
str = fullpath(mainpath,str);
zip_files = dir(str);
More Answers (0)
See Also
Categories
Find more on File Operations 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!