Check if URL exists
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Does anyone know how to check if a URL exists? The function exist seems to only work of file paths through a computer.
0 comentarios
Respuestas (1)
Walter Roberson
el 30 de Jul. de 2012
It is possible to detect that a URL does exist, but it is not always possible to detect that a URL does not exist compared to it existing but you not being permitted to examine it.
5 comentarios
Edward Strobach
el 26 de Abr. de 2017
Editada: Walter Roberson
el 26 de Abr. de 2017
I found for files online, that I can create a function that examines, iteratively, the presence of a file within a URL to determine whether or not it exists.
Example
function [info,status] = FileExists(t)
t = num2str(8965);
url = strcat('http://podaac-opendap.jpl.nasa.gov/opendap/allData/oscar/preview/L4/oscar_third_deg/oscar_vel',t,'.nc.gz');[~,status] = urlread(url);
filename = strcat('oscar_vel',t,'.nc.gz');
try
Info = ncinfo(url);
status = 1;
catch
Info = [];
status = 0;
end
If status is 1, then file exists, if status is 0, the file doesnt' exist. You can use a tilde for the first output within the square brackets to suppress the output if you only want to look at the status
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!