changelog shortlog tags changeset files revisions annotate raw

scripts/miscellaneous/fullfile.m

changeset 10289: 4b124317dc38
parent:3422f39573b1
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (47 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2003, 2005, 2006, 2007, 2008 John W. Eaton
2##
3## This file is part of Octave.
4##
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.
9##
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.
14##
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/>.
18
19## -*- texinfo -*-
20## @deftypefn {Function File} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file})
21## Return a complete filename constructed from the given components.
22## @seealso{fileparts}
23## @end deftypefn
24
25function filename = fullfile (varargin)
26
27 if (nargin > 0)
28 ## Discard all empty arguments
29 varargin(cellfun (@isempty, varargin)) = [];
30 nargs = numel (varargin);
31 if (nargs > 1)
32 filename = varargin{1};
33 if (strcmp (filename(end), filesep))
34 filename(end) = "";
35 endif
36 for i = 2:nargs
37 tmp = varargin{i};
38 if (i < nargs && strcmp (tmp(end), filesep))
39 tmp(end) = "";
40 elseif (i == nargs && strcmp (tmp, filesep))
41 tmp = "";
42 endif
43 filename = cstrcat (filename, filesep, tmp);
44 endfor
45 elseif (nargs == 1)
46 filename = varargin{1};
47 else
48 filename = "";
49 endif
50 else
51 print_usage ();
52 endif
53
54endfunction
55
56%!shared fs, fsx, xfs, fsxfs, xfsy
57%! fs = filesep ();
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)