MATLAB: Can anyone explain me what this line do strcmp(D(i).name,’..’)

string operation

I am trying to read the number of images in a folder the following code. Can anyone explain this?
if not(strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db'))
imgcount = imgcount + 1; % Number of all images in the training database
end

Best Answer

The code is obviously meant to be in a loop and the D most likely originates from a dir command. Its purpose is to count the number of files in the directory other than 'thumbs.db' and the '.' and '..' directories that matlab stupidly returns.
It assumes that all files in the directory are images and that there are no subdirectories. Otherwise imgcount will be wrong.
It's also not very well written. There is no need for a loop. You could replace:
for i = 1:numel(D) %I assume that's what it looks like
if not(strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db'))
imgcount = imgcount + 1; % Number of all images in the training database
end
end
with:
filenames = {D.name};
imgcount = sum(~strcmp(filenames, '.') & ~strcmp(filenames, '..') & ~strcmp(filenames, 'thumbs.db'));