How do I check if a file on a website exists?
조회 수: 7 (최근 30일)
이전 댓글 표시
I want to read in image files from my online database.
I would like to check my website to see if the file exists before attempting to load it into the workspace.
For Example I would like to do (simplified):
E = exist('http://www.mywebsite.com/images/1.png);
if E ~= 0
IMG = imread('http://www.mywebsite.com/images/1.png);
else
IMG = zeros(X,Y);
end
Thanks in Advance!
댓글 수: 0
채택된 답변
Sean de Wolski
2012년 10월 24일
You could just use a try/catch block.
try
IMG = imread('http://www.mywebsite.com/images/1.png);
catch
IMG = zeros(X,Y);
end
추가 답변 (1개)
Erick Oberstar
2015년 12월 15일
you can use urlread also
[str,status] = urlread('http://www.mywebsite.com/images/1.png');
if status
IMG = imread('http://www.mywebsite.com/images/1.png');
else
disp('URL read of link was unsuccessful')
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!