File: CheckDirs.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (34 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (6)
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
function CheckDirs(dirs,mode)
% CheckDirs(dirs,mode):
% Iterates over all fields in struct 'dirs' and checks whether the Contents are existing directory addresses.
% mode == 'check': Display an error if this is not the case.
% mode == 'make' : Creates the directory if it doesnt exist.
% Default mode is 'check'.
% JvR 2008-03-31

psychassert(isstruct(dirs),'Piss off with your type ''%s''',class(dirs)) % Input must be a struct.

if nargin==1
    mode = 'check';                                            	% No mode input? Use default (check)
end

switch mode
    case 'make'
        structfun(@makedirs,dirs);                              % Apply function makedirs to each field in the struct
    case 'check'
        structfun(@checkem,dirs);                               % Apply function checkem to each field in the struct
    otherwise
        error('\nUnknown MODE input argument "%s"! \n\nRecognised inputs: ''check'' or ''make''.',mode);
end
end

function checkem(in)
psychassert(isdir(in),'Directory %s not found',in);          % Directory doesn't exist; error.
end

function makedirs(in)
if ~isdir(in)
    mkdir(in);                                              % Directory doesn't exist; create.
    disp(sprintf('Directory %s created.',in));
end
end