-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathremoveBadFiles.m
More file actions
23 lines (22 loc) · 795 Bytes
/
removeBadFiles.m
File metadata and controls
23 lines (22 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function fileList = removeBadFiles(directory)
% REMOVEBADFILES remove bad files and subdirs
% (thx to Jonas from stackoverflow)
% select all input files (should be sorted with leading zeros)
fileList = dir(directory);
% remove all folders
isBadFile = cat(1,fileList.isdir); % all directories are bad
% loop to identify hidden files
for iFile = find(~isBadFile)'; % loop only non-dirs
% on UNIX, hidden files start with a dot
isBadFile(iFile) = strcmp(fileList(iFile).name(1),'.');
if ~isBadFile(iFile) && ispc
% check for hidden Windows files - only works on Windows
[~,stats] = fileattrib(fullfile(directory,fileList(iFile).name));
if stats.hidden
isBadFile(iFile) = true;
end
end
end
% remove bad files
fileList(isBadFile) = [];
end