0001 function newfp = slchangefilepart(fp, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 if isempty(varargin)
0022 newfp = fp;
0023 else
0024
0025 opts.parent = '';
0026 opts.name = '';
0027 opts.title = '';
0028 opts.ext = '';
0029 opts = slparseprops(opts, varargin{:});
0030
0031 if ~isempty(opts.ext)
0032 if opts.ext(1) ~= '.'
0033 error('sltoolbox:invalidarg', ...
0034 'The extension string should start with a dot . ');
0035 end
0036 end
0037
0038 [p.parent, p.title, p.ext] = fileparts(fp);
0039
0040 if isempty(opts.name)
0041 p = updatefields(p, opts, {'parent', 'title', 'ext'});
0042 newfp = fullfile(p.parent, [p.title, p.ext]);
0043 else
0044 if ~isempty(opts.title) || ~isempty(opts.ext)
0045 error('sltoolbox:invalidarg', ...
0046 'When name is specified, title and ext should not be');
0047 end
0048 p = updatefields(p, opts, {'parent', 'name'});
0049 newfp = fullfile(p.parent, p.name);
0050 end
0051
0052 end
0053
0054
0055
0056
0057 function S = updatefields(S, newS, fns)
0058
0059 nf = length(fns);
0060 for i = 1 : nf
0061 f = fns{i};
0062 if ~isempty(newS.(f))
0063 S.(f) = newS.(f);
0064 end
0065 end
0066
0067
0068
0069
0070
0071
0072
0073
0074