How to check if a file of certain type exists in folder?
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aadil
el 6 de Sept. de 2012
Comentada: Devalla lakshmipathirao
el 7 de Sept. de 2020
Hi All,
How can I check if a .pdf file exists in a folder
I know I can use the Exist command if I know the full filename, but I don't have the file name
Thanks,
EDIT: I will need the output as true or false
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 6 de Sept. de 2012
Editada: Azzi Abdelmalek
el 6 de Sept. de 2012
any(size(dir([yourFolderName '/*.pdf' ]),1))
9 comentarios
Más respuestas (1)
Dr. Seis
el 6 de Sept. de 2012
Editada: Dr. Seis
el 6 de Sept. de 2012
You could try doing something like:
dir_struct = dir( fullfile(your_path,'*pdf') );
if numel(dir_struct) == 0
% then there are no files with extension "pdf"
else
% there is a "pdf" file in your directory
% dir_struct(1).name gives the file name of the first "pdf" file listed
end
3 comentarios
Devalla lakshmipathirao
el 7 de Sept. de 2020
Using the code by @Dr. Seis, how can i check if .pdf exists i.e, not based on number of elements but rather by checking the file name .
Ver también
Categorías
Más información sobre File Operations 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!