time | calls | line |
---|
| | 1 | function f = fullfile(varargin)
|
| | 2 | %FULLFILE Build full file name from parts.
|
| | 3 | % F = fullfile(FOLDERNAME1, FOLDERNAME2, ..., FILENAME) builds a full
|
| | 4 | % file specification F from the folders and file name specified. Input
|
| | 5 | % arguments FOLDERNAME1, FOLDERNAME2, etc. and FILENAME can be strings,
|
| | 6 | % a scalar cell string, or same-sized cell arrays of strings. The output
|
| | 7 | % of fullfile is conceptually equivalent to
|
| | 8 | %
|
| | 9 | % F = [FOLDERNAME1 filesep FOLDERNAME2 filesep ... filesep FILENAME]
|
| | 10 | %
|
| | 11 | % except that care is taken to handle the cases when the folders begin or
|
| | 12 | % end with a file separator.
|
| | 13 | %
|
| | 14 | % Examples
|
| | 15 | % % To build platform dependent paths to files:
|
| | 16 | % fullfile(matlabroot,'toolbox','matlab','general','Contents.m')
|
| | 17 | %
|
| | 18 | % % To build platform dependent paths to a folder:
|
| | 19 | % fullfile(matlabroot,'toolbox','matlab',filesep)
|
| | 20 | %
|
| | 21 | % % To build a collection of platform dependent paths to files:
|
| | 22 | % fullfile(toolboxdir('matlab'),'iofun',{'filesep.m';'fullfile.m'})
|
| | 23 | %
|
| | 24 | % See also FILESEP, PATHSEP, FILEPARTS.
|
| | 25 |
|
| | 26 | % Copyright 1984-2012 The MathWorks, Inc.
|
| | 27 |
|
< 0.01 | 121 | 28 | narginchk(1, Inf);
|
| 121 | 29 | fileSeparator = filesep;
|
| 121 | 30 | argIsACell = cellfun('isclass', varargin, 'cell');
|
< 0.01 | 121 | 31 | theInputs = varargin;
|
| 121 | 32 | f = theInputs{1};
|
| 121 | 33 | try
|
| 121 | 34 | if nargin == 1
|
| | 35 | f = refinePath(f);
|
| | 36 | return;
|
| 121 | 37 | elseif any(argIsACell)
|
| | 38 | theInputs(cellfun(@(x)~iscell(x)&&isempty(x), theInputs)) = [];
|
| 121 | 39 | else
|
| 121 | 40 | theInputs(cellfun('isempty', theInputs)) = '';
|
| 121 | 41 | end
|
| | 42 |
|
| 121 | 43 | if length(theInputs)>1
|
0.02 | 121 | 44 | theInputs{1} = ensureTrailingFilesep(theInputs{1});
|
| 121 | 45 | end
|
| 121 | 46 | if ~isempty(theInputs)
|
| 121 | 47 | theInputs(2,:) = {fileSeparator};
|
| 121 | 48 | theInputs{2,1} = '';
|
| 121 | 49 | theInputs(end) = '';
|
| 121 | 50 | if any(argIsACell)
|
| | 51 | f = strcat(theInputs{:});
|
| 121 | 52 | else
|
| 121 | 53 | f = [theInputs{:}];
|
| 121 | 54 | end
|
| 121 | 55 | end
|
| 121 | 56 | f = refinePath(f);
|
| | 57 | catch exc
|
| | 58 | locHandleError(exc, theInputs(1,:));
|
| | 59 | end
|
| 121 | 60 | end
|