MATLAB Answers

how to make unzip faster in matlab?

82 ビュー (過去 30 日間)
sandy
sandy 2013 年 8 月 28 日
回答済み: Wouter 2017 年 8 月 7 日
i have 50000 .zip files..i need to unzip and process with the files inside those zip files. i coded to unzip in a loop.but its very slow and taked 2 hr to complete unzip of all 5000 files.any way to speedup the unzipping in matlab?

  0 件のコメント

Sign in to comment.

回答 (5 件)

Wouter
Wouter 2017 年 8 月 7 日
I had the same issue. Using an external program (7-zip) solved the issue for me. Extracting and repacking 1000+ zip files was > 27x faster than the Matlab unzip function.
Is used it like this to unpack:
sys_cmd_unzip = @(z,d) ['"C:\Program Files\7-Zip\7z.exe" e -y -r -o"' d '" "' z '" *'];
cellfun(@(z,d) system(sys_cmd_unzip(z,d)), all_zip_files, new_zip_file_dirs,'uniformoutput',false)
and like this to repack:
sys_cmd_unzip = @(zd) ['"C:\Program Files\7-Zip\7z.exe" a -y -sdel -tzip -r "' zd '.zip" "' zd '/*";'];
cellfun(@(zfd) system(sys_cmd_unzip(zfd)),new_zip_file_dirs,'uniformoutput',false)
cellfun(@(zfd) rmdir(zfd), new_zip_file_dirs) % remove directory where files where stored.
for the command line options of 7zip, see help of 7z.exe.

  0 件のコメント

Sign in to comment.


David Sanchez
David Sanchez 2013 年 8 月 28 日
You can use external software with " ! ", if you use unzip, then, call it this way:
! unzip your_file.zip

  1 件のコメント

sandy
sandy 2013 年 8 月 28 日
thanks... this is applicable for one zip file..but how to use this(!) for 5500 files in a loop..it showing error?

Sign in to comment.


Walter Roberson
Walter Roberson 2013 年 8 月 28 日
Have you considered calling upon an external unzipping program by using system() ?

  1 件のコメント

sandy
sandy 2013 年 8 月 28 日
this s my code of unzipping for N number of files.(nearly 5500).it took 3hr to finish all process, how can i use system() to access external program..help me
zip_files=dir('*.zip');
for k=1:numel(zip_files)
unzip(zip_files(k).name,'output');
T ='.\Extracted Files.\*.tim';
R='.\Extracted Files.\*.run';
movefile(T,'.\T Files');
movefile(R,'.\R Files');
end

Sign in to comment.


David Sanchez
David Sanchez 2013 年 8 月 28 日
You can try something like this:
my_zips = dir('*.zip');
for k=1:numel(my_zips)
tmp_str = horzcat('unzip ', my_zips(k).name);
system(tmp_str);
end
This will unzip all your zip files.

  2 件のコメント

sandy
sandy 2013 年 8 月 29 日
his code takes more time to unzip all my files.can you suggest more specific way to reduce unzipping times for 55000 zip files
David Sanchez
David Sanchez 2013 年 8 月 29 日
Sometimes you can not reduce any more the time taken to perform some tasks. 5000 files are a whole lot of files to unzip. You say it takes 2 hours to perform the job, that means you are unzipping a file every 1.44 seconds, which is not a long time to unzip a file of small size.

Sign in to comment.


Patrick Lloyd
Patrick Lloyd 2015 年 4 月 15 日
I understand the post is somewhat old but it may be useful for people looking to speed up their zip extraction. If you don't specifically need every single file in the archive at once, you can use something like:
zip_file = 'foo.zip'
destination_folder = 'C:\foo\bar\'
system(['unzip ' '"' zip_file '"' ' file_inside_to_extract.txt' ' -d ' '"' ...
destination_folder '"'])
The system unzip command (for Windows at least) allows you to pull out specific files from the archive.

  0 件のコメント

Sign in to comment.


Translated by