annotate scripts/miscellaneous/fullfile.m @ 19248:8cc4a9bb253b

fullfile.m: Match documentation name to function variable name. * fullfile.m: Match documentation name to function variable name. Add seealso link to filesep. * fileparts.m: Change seealso link to filesep.
author Rik <rik@octave.org>
date Sat, 04 Oct 2014 20:06:27 -0700
parents 1111d2d5ff95
children c304687571c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19219
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2014 Carnë Draug
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
2 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
4 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
9 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
14 ##
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
18
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
19248
8cc4a9bb253b fullfile.m: Match documentation name to function variable name.
Rik <rik@octave.org>
parents: 19220
diff changeset
20 ## @deftypefn {Function File} {@var{filename} =} fullfile (@var{dir1}, @var{dir2}, @dots{}, @var{file})
8cc4a9bb253b fullfile.m: Match documentation name to function variable name.
Rik <rik@octave.org>
parents: 19220
diff changeset
21 ## @deftypefnx {Function File} {@var{filenames} =} fullfile (@dots{}, @var{files})
19219
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
22 ## Build complete filename from separate parts.
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
23 ##
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
24 ## Joins any number of path components intelligently. The return value
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
25 ## is the concatenation of each component with exactly one file separator
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
26 ## between each non empty part.
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
27 ##
19220
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
28 ## If the last component part is a cell array, returns a cell array of
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
29 ## filepaths, one for each element in the last component, e.g.:
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
30 ##
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
31 ## @example
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
32 ## @group
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
33 ## fullfile ("/home/username", "data", @{"f1.csv", "f2.csv", "f3.csv"@})
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
34 ## @result{} /home/username/data/f1.csv
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
35 ## /home/username/data/f2.csv
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
36 ## /home/username/data/f3.csv
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
37 ## @end group
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
38 ## @end example
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
39 ##
19248
8cc4a9bb253b fullfile.m: Match documentation name to function variable name.
Rik <rik@octave.org>
parents: 19220
diff changeset
40 ## @seealso{fileparts, filesep}
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
41 ## @end deftypefn
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
42
19219
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
43 ## Author: Carnë Draug <carandraug@octave.org>
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
44
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
45 function filename = fullfile (varargin)
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
46
19220
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
47 if (nargin && iscell (varargin{end}))
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
48 filename = cellfun (@(x) fullfile (varargin{1:end-1}, x), varargin{end},
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
49 "UniformOutput", false);
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
50 else
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
51 non_empty = cellfun ("isempty", varargin);
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
52 filename = strjoin (varargin(! non_empty), filesep);
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
53 filename(strfind (filename, [filesep filesep])) = "";
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
54 endif
4265
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
55
48897c78c52b [project @ 2003-01-03 06:04:29 by jwe]
jwe
parents:
diff changeset
56 endfunction
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
57
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
59 %!shared fs, fsx, xfs, fsxfs, xfsy
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
60 %! fs = filesep ();
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
61 %! fsx = [fs "x"];
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
62 %! xfs = ["x" fs];
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
63 %! fsxfs = [fs "x" fs];
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14363
diff changeset
64 %! xfsy = ["x" fs "y"];
7288
1885f4c7e4b3 [project @ 2007-12-11 17:19:44 by jwe]
jwe
parents: 7017
diff changeset
65 %!assert (fullfile (""), "")
7514
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
66 %!assert (fullfile (fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
67 %!assert (fullfile ("", fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
68 %!assert (fullfile (fs, ""), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
69 %!assert (fullfile ("", fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
70 %!assert (fullfile ("x"), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
71 %!assert (fullfile ("", "x"), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
72 %!assert (fullfile ("x", ""), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
73 %!assert (fullfile ("", "x", ""), "x")
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
74 %!assert (fullfile ("x", "y"), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
75 %!assert (fullfile ("x", "", "y"), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
76 %!assert (fullfile ("x", "", "y", ""), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
77 %!assert (fullfile ("", "x", "", "y", ""), xfsy)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
78 %!assert (fullfile (fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
79 %!assert (fullfile (fs, fs), fs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
80 %!assert (fullfile (fs, "x"), fsx)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
81 %!assert (fullfile (fs, xfs), fsxfs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
82 %!assert (fullfile (fsx, fs), fsxfs)
4f6a73fd8df9 fullfile: improve handling of args ending with filesep
John W. Eaton <jwe@octave.org>
parents: 7288
diff changeset
83 %!assert (fullfile (fs, "x", fs), fsxfs)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
84
19219
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
85 %!assert (fullfile ("a/", "/", "/", "b", "/", "/"), "a/b/")
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
86 %!assert (fullfile ("/", "a/", "/", "/", "b", "/", "/"), "/a/b/")
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
87 %!assert (fullfile ("/a/", "/", "/", "b", "/", "/"), "/a/b/")
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
88
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
89 ## different on purpose so that "fullfile (c{:})" works for empty c
8ca827e18349 fullfile: complete rewrite of the function.
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
90 %!assert (fullfile (), "")
19220
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
91
1111d2d5ff95 fullfile.m: add support for multiple paths with cell array for last component.
Carnë Draug <carandraug@octave.org>
parents: 19219
diff changeset
92 %!assert (fullfile ("a", "b", {"c", "d"}), {"a/b/c", "a/b/d"})
19248
8cc4a9bb253b fullfile.m: Match documentation name to function variable name.
Rik <rik@octave.org>
parents: 19220
diff changeset
93