-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderFromFolder.m
More file actions
44 lines (38 loc) · 1.35 KB
/
FolderFromFolder.m
File metadata and controls
44 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function [fold,nfold] = FolderFromFolder(folder,mode)
% [fold,nfold] = FolderFromFolder(folder,mode)
%
% Returns struct with all directories in directory FOLDER.
% MODE specifies whether an error is displayed when no directories are
% found (default). If MODE is 'silent', only a message will will be
% displayed in the command window, if 'ssilent', no notification will be
% produced at all.
% 2007 IH Wrote it.
% 2007 IH&DN Various additions
% 2008-08-06 DN All file properties now in output struct
% 2009-02-14 DN Now returns all folders except '..' and '.', code
% optimized
% 2010-07-02 DN Fixed typo in warning when silent and no files found, got
% rid of for loop
% 2012-06-04 DN Now also have ssilent mode for no output at all
if nargin >= 2 && strcmp(mode,'silent')
silent = 1;
elseif nargin >= 2 && strcmp(mode,'ssilent')
silent = 2;
else
silent = 0;
end
fold = dir(folder);
fold = fold([fold.isdir]);
% now skip '..' and '.', do not want to assume they are the first two
% elements returned
qremove = ismember({fold.name},{'.','..'});
fold(qremove) = [];
nfold = length(fold);
if nfold==0
if silent==1
fprintf('FolderFromFolder: No folders found in: %s\n',folder);
fold = [];
elseif ~silent
error('FolderFromFolder: No folders found in: %s',folder);
end
end