How to check if a file of certain type exists in folder?
157 views (last 30 days)
Aadil on 6 Sep 2012
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
EDIT: I will need the output as true or false
More Answers (1)
Dr. Seis on 6 Sep 2012
Edited: Dr. Seis on 6 Sep 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"
% there is a "pdf" file in your directory
% dir_struct(1).name gives the file name of the first "pdf" file listed