(Download image)
4 ビュー (過去 30 日間)
古いコメントを表示
If I have a txt file, which contains the url that downloads images, how do we write the script to do that?
e.g. txt file information:
.. .. ...
0 件のコメント
採用された回答
Walter Roberson
2016 年 2 月 5 日
編集済み: Walter Roberson
2016 年 2 月 5 日
projectdir = fullfile(pwd, 'saved_images'); %location to store the files
if ~exist(projectdir, 'dir')
mkdir(projectdir);
end
fid = fopen('TheFile.txt', 'rt');
imcount = 0;
while true
this_url = fgetl(fid);
if ~ischar(this_url)
break; %end of file
end
if isempty(strtrim(this_url))
continue %empty line, probably near end of file
end
[url_path, url_img, url_ext] = fileparts(this_url);
dest_file = fullfile(projectdir, [url_img url_ext]);
if exist(dest_file, 'file')
fprintf('skipping existing %s\n', dest_file);
imcount = imcount + 1;
urls{imcount} = this_url;
img_files{imcount} = dest_file;
%img_content{imcount} = imread(dest_file);
continue;
end
fprintf('loading ... %s\n', url_img);
try
urlwrite(this_url, dest_file);
imcount = imcount + 1;
urls{imcount} = this_url;
img_files{imcount} = dest_file;
%img_content{imcount} = imread(dest_file);
catch
fprintf('failed downloading %s from "%s"\n', url_img, this_url);
end
end
6 件のコメント
Walter Roberson
2016 年 2 月 5 日
On social media I do not talk about programming much. I talk about programming so much here that social media is my escape from that, where I post about politics or post random science stories or (more often) post weird news like escaping Llamas, or Florida Man. It is not a "professional" presence and it won't help you learn to program. But if I haven't discouraged you sufficiently, you can find me on Google Plus under the same name I use here. My icon is a Japanese stone statue of a type of Japanese daemon.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Downloads についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!