MATLAB: Index for subfolders without *.pdf files

MATLAB

Hi guys. I have one folder which contains several 100 subfolders. I need to index for subfolder with does not contain a pdf file, and locate these folders. Hwo can I do this? Thanks a lot

Best Answer

Simpler and more robust:
D = 'path to the main folder';
S = dir(fullfile(D,'*'));
N = setdiff({S([S.isdir]).name},{'.','..'});
F = @(s)isempty(dir(fullfile(D,s,'*.pdf')));
X = cellfun(F,N)
It returns logical indices, simply use FIND for subscript indices.
The names of the folders without .PDF files:
N(X)