File: FolderFromFolder.m

package info (click to toggle)
psychtoolbox-3 3.0.9%2Bsvn2579.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 63,408 kB
  • sloc: ansic: 73,310; cpp: 11,139; objc: 3,129; sh: 1,669; python: 382; php: 272; makefile: 172; java: 113
file content (40 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download
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
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.

% 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

if nargin == 2 && strcmp(mode,'silent')
    silent = true;
else
    silent = false;
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
        fprintf('FolderFromFolder: No folders found in: %s\n',folder);
        fold = [];
    elseif ~silent
        error('FolderFromFolder: No folders found in: %s',folder);
    end
end