1## Copyright (C) 2003, 2005, 2006, 2007, 2008 John W. Eaton
3## This file is part of Octave.
5## Octave is free software; you can redistribute it and/or modify it
6## under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
10## Octave is distributed in the hope that it will be useful, but
11## WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13## General Public License for more details.
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
20## @deftypefn {Function File} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file})
21## Return a complete filename constructed from the given components.
25function filename = fullfile (varargin)
28 ## Discard all empty arguments
29 varargin(cellfun (@isempty, varargin)) = [];
30 nargs = numel (varargin);
32 filename = varargin{1};
33 if (strcmp (filename(end), filesep))
38 if (i < nargs && strcmp (tmp(end), filesep))
40 elseif (i == nargs && strcmp (tmp, filesep))
43 filename = cstrcat (filename, filesep, tmp);
46 filename = varargin{1};
56%!shared fs, fsx, xfs, fsxfs, xfsy
58%! fsx = cstrcat (fs, "x");
59%! xfs = cstrcat ("x", fs);
60%! fsxfs = cstrcat (fs, "x", fs);
61%! xfsy = cstrcat ("x", fs, "y");
62%!assert (fullfile (""), "")
63%!assert (fullfile (fs), fs)
64%!assert (fullfile ("", fs), fs)
65%!assert (fullfile (fs, ""), fs)
66%!assert (fullfile ("", fs), fs)
67%!assert (fullfile ("x"), "x")
68%!assert (fullfile ("", "x"), "x")
69%!assert (fullfile ("x", ""), "x")
70%!assert (fullfile ("", "x", ""), "x")
71%!assert (fullfile ("x", "y"), xfsy)
72%!assert (fullfile ("x", "", "y"), xfsy)
73%!assert (fullfile ("x", "", "y", ""), xfsy)
74%!assert (fullfile ("", "x", "", "y", ""), xfsy)
75%!assert (fullfile (fs), fs)
76%!assert (fullfile (fs, fs), fs)
77%!assert (fullfile (fs, "x"), fsx)
78%!assert (fullfile (fs, xfs), fsxfs)
79%!assert (fullfile (fsx, fs), fsxfs)
80%!assert (fullfile (fs, "x", fs), fsxfs)