Save the result of urlread as file in current directory instead of a variable in the workspace

3 ビュー (過去 30 日間)
I would like to find an answer to unzip the result of the urlread funtion that's a zip archive. The result experienced is the fallowing:
if true
>> urlread('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.zip?2d1147c9cf376b26c445ffee4d2b37d1');
>> unzip(ans)
??? Error using ==> checkfilename>validateFilename at 184
Function UNZIP was unable to find file 'PK'.
Error in ==> checkfilename at 50 [fullfilename, fid] = validateFilename( ...
Error in ==> parseUnArchiveInputs at 87 [archiveFilename, url] = checkfilename(archiveFilename, validExtensions, ...
Error in ==> unzip at 52 [zipFilename, outputDir, url, urlFilename] = parseUnArchiveInputs( ...
>> unzip('exch.zip') Warning: Permission denied to overwrite file ".\eurofxref-hist.csv". > In iofun\private\extractArchive>extractArchiveEntry at 108 In iofun\private\extractArchive at 52 In unzip at 92 >> unzip('exch.zip') >> end
Also I didn't find how to overwrite the unziped file if this is needed. If I need to download a zip file with urlread() how I can save it in current directory instead of a variable in the workspace. Many thanks for reading this post and answers.

採用された回答

Jan
Jan 2014 年 2 月 26 日
編集済み: Jan 2014 年 2 月 26 日
You can save the file using urlwrite instead of urlread:
file = fullfile(cd, 'TheZipFile.zip');
urlwrite(['http://www.ecb.europa.eu/stats/eurofxref/eurofxref-', ...
'hist.zip?2d1147c9cf376b26c445ffee4d2b37d1'], ...
file);
unzip(file);
urlread replies the contents of the read file as a variable, but unzip expects a file name.
  2 件のコメント
VR
VR 2014 年 2 月 26 日
Thanks very much for your response. It's works.
Reema Alhassan
Reema Alhassan 2018 年 5 月 23 日
編集済み: Reema Alhassan 2018 年 5 月 23 日
hi Jan what if I have a matrix of urls how can I do it? if I put variable instead of the first field in urlwrite() function I get an error
thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDownloads についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by