-
Notifications
You must be signed in to change notification settings - Fork 1
/
complete_filenames.m
58 lines (49 loc) · 1.7 KB
/
complete_filenames.m
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
45
46
47
48
49
50
51
52
53
54
55
56
function outfiles = complete_filenames (infiles, ...
def_path, def_name, def_ext, ...
options)
%COMPLETE_FILENAMES (ps-utils): add default path and extension to filenames.
% OUTFILES = COMPLETE_FILENAMES(INFILES, DEF_PATH, DEF_NAME, DEF_EXT, OPTIONS)
%
% infiles: a list of filenames. If no path, name or extension is
% specified, one will be filled in.
% def_path, def_name, def_ext: defaults for each path component.
% If any of these parameters are '' then that component will not
% be added to an infilename even if the component is missing.
% option: cell array of string options: 'error' is default, means die
% if there is no component and '' specified, 'ignoremissing' means ignore it
% outfiles: the list with path and extension completed.
%
% MH - http://github.com/histed/tools-mh
[frows fcols] = size (infiles);
outfiles = [];
if ~exist ('options'),
ignoremissing = 0;
else
flag_names = {'error', 'ignoremissing'};
[a ignoremissing] = process_cell_flags (flag_names, options);
end
for ifile = 1:frows,
[path name ext] = fileparts (deblank(infiles(ifile,:)));
if isempty (path),
if isempty(def_path) & ~ignoremissing
error ('Missing required path.'); return
else
path = def_path;
end
end
if isempty (ext),
if isempty (def_ext) & ~ignoremissing
error ('Missing required ext.');
else
ext = def_ext;
end
end
if isempty (name),
if isempty (def_name) & ~ignoremissing
error ('Missing required file/dir name');
else
name = def_name;
end
end
outfiles = strvcat (outfiles, fullfile (path, [name ext]));
end