unzip a list of urls from txt file

1 view (last 30 days)
this is my code I read the urls from a txt file but now I need to unzip them all
when I unzip them I always get the same error
could anyone please show me the code of doing that thanks.
file = input('Enter file name: ','s'); % prompt the user to enter file name
str= fileread(file);
% a pattern for reading urls
C = regexpi(str, ...
['((http|https|ftp|file)://|www\.|ftp\.)',...
'[-A-Z0-9+&@#/%=~_|$?!:,.]*[A-Z0-9+&@#/%=~_|$]'], 'match');
C{:};
for k = 1:numel(C)
element=C(k);
% disp(C(k));
unzip(element,'MATLAB');
end
the error is: Error using exist The first input to exist must be a string scalar or character vector.
Error in parseUnArchiveInputs (line 74) if exist(archiveFilename,'dir') && ~isempty(dir(archiveFilename))
Error in unzip (line 57) [zipFilename, outputDir, url, urlFilename] = parseUnArchiveInputs( ...
Error in project2 (line 17) unzip(element,'MATLAB');

Accepted Answer

Jan
Jan on 23 May 2018
Edited: Jan on 23 May 2018
The line
C{:};
performs nothing. Delete it.
unzip needs a file name as char vector as first input, but element=C(k) creates a scalar cell string. Use this instead:
element = C{k}; % Curly braces
By the way, I'm not sure if "unzipping an URL" is a meaningful task. It depends on the contents of the data.
  3 Comments
Jan
Jan on 30 May 2018
@Reema Alhassan: Please post comments in the section for comments. Thanks.
Do you provide the URL as input to unzip or did you download the file and call unzip afterwards? Matlab's unzip is a java implementation. I assume calling e.g. 7zip will be much faster. And I'm not sure if unzip works at all for tar-gnuzip files. Did you test this?
Reema Alhassan
Reema Alhassan on 30 May 2018
I have tried gunzip with untar together and and it is working thanks a lot ..

Sign in to comment.

More Answers (0)

Categories

Find more on File Compression 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!