counting files within directories: error with thumbs.db files
10 views (last 30 days)
Show older comments
The directories that contain thumbs.db (microsoft OS win 7, matlab 2012) files always include 1 more file cnt than the actual count provided by [r,s]=size(ls(dirArray)) So when we automate the output of all the directories and files through a for loop, from cell arrays that contain the directory path and another for the file names. When I delete the thumbs.db file, the file output occurs without the error"index greater than matrix dimensions" However, when manually counting and cross referencing the files within a directory, the tumbs.db file appeared but other random files did not appear i the cell array listing. The files did all appear in a structure of S=dir(pwd) Why does the file count get corrupted when thumb.db fiiles are wihin a directoryy?
0 Comments
Answers (1)
Image Analyst
on 25 Jun 2012
This 3 (key) line solution is probably not the most compact way to do it, but since no one has answered for hours....
% Get all files, including Thumbs if we can see hidden files.
allFiles = dir(pwd)
% Find out what row Thumbs.db occurs in.
strAllFiles = strvcat(allFiles.name)
tf = ismember(strAllFiles, {'Thumbs.db'});
% Now take everything except Thumbs.db.
noThumbs = allFiles(~tf)
% Let's check to see if it worked.
doubleCheckResult = strvcat(noThumbs.name)
1 Comment
Jan
on 26 Jun 2012
There is no need to use STRVCAT to create a padded CHAR matrix. More efficient:
allNames = {allFiles.name};
cleanFiles = allFiles(~strcmpi(allNames, 'Thumbs.db'));
See Also
Categories
Find more on File Operations 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!