Can anyone explain me what this line do strcmp(D(i).name,'..')?
Show older comments
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
Accepted Answer
More Answers (1)
Henrik
on 8 Dec 2014
strcmp(D(i).name,'.'
this compares the string in D(i).name to '.'. If the string is indeed '.', it returns TRUE (in MATLAB, this is the same as 1).
Similarly for the two other strcmp: if the string is equal to '..' or 'Thumbs.db' it returns true.
The | between the three checks means either. So
strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db')
is true if the string in D(i).name is either '.', '..' or 'Thumbs.db'.
The not in front of all this means that imcount will increase by 1 if the string in D(i).name is neither '.', '..' nor 'Thumbs.db'
3 Comments
Titus Edelhofer
on 8 Dec 2014
In summary: it looks as if someone calls "dir" and loops over the result to count all files that are not "." (current folder), ".." which is the parent folder or "Thumbs.db" which is a file created by Windows explorer ...
Titus
Henrik
on 8 Dec 2014
So the imgcounter is actually just counting the number of files in the directory?
Vinay Kumar
on 8 Dec 2014
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!