7017
|
1 ## Copyright (C) 2003, 2005, 2006, 2007 John W. Eaton |
4265
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
4265
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
4265
|
18 |
|
19 ## -*- texinfo -*- |
4350
|
20 ## @deftypefn {Function File} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file}) |
|
21 ## Return a complete filename constructed from the given components. |
5835
|
22 ## @seealso{fileparts} |
4265
|
23 ## @end deftypefn |
|
24 |
|
25 function filename = fullfile (varargin) |
|
26 |
|
27 if (nargin > 0) |
7288
|
28 filename = ""; |
|
29 for first = 1:nargin |
|
30 tmp = varargin{first}; |
|
31 if (! isempty (tmp)) |
|
32 filename = tmp; |
|
33 break; |
|
34 endif |
|
35 endfor |
|
36 for i = first+1:nargin |
4265
|
37 tmp = varargin{i}; |
7288
|
38 if (! isempty (tmp)) |
|
39 if (strcmp (tmp(1), filesep)) |
|
40 tmp(1) = ""; |
|
41 endif |
|
42 if (i < nargin && strcmp (tmp(end), filesep)) |
|
43 tmp(end) = ""; |
|
44 endif |
|
45 filename = strcat (filename, filesep, tmp); |
4265
|
46 endif |
|
47 endfor |
|
48 else |
6046
|
49 print_usage (); |
4265
|
50 endif |
|
51 |
|
52 endfunction |
7288
|
53 |
|
54 %!assert (fullfile (""), "") |
|
55 %!assert (fullfile (filesep ()), filesep ()) |
|
56 %!assert (fullfile ("", filesep ()), filesep ()) |
|
57 %!assert (fullfile (filesep (), ""), filesep ()) |
|
58 %!assert (fullfile ("", filesep ()), filesep ()) |
|
59 %!assert (fullfile ("foo"), "foo") |
|
60 %!assert (fullfile ("", "foo"), "foo") |
|
61 %!assert (fullfile ("foo", ""), "foo") |
|
62 %!assert (fullfile ("", "foo", ""), "foo") |
|
63 %!assert (fullfile ("foo", "bar"), strcat ("foo", filesep (), "bar")) |
|
64 %!assert (fullfile ("foo", "", "bar"), strcat ("foo", filesep (), "bar")) |
|
65 %!assert (fullfile ("foo", "", "bar", ""), strcat ("foo", filesep (), "bar")) |
|
66 %!assert (fullfile ("", "foo", "", "bar", ""), strcat ("foo", filesep (), "bar")) |