comparison scripts/path/genpath.m @ 5810:34010a1e9aea

[project @ 2006-05-11 06:41:51 by jwe]
author jwe
date Thu, 11 May 2006 06:41:51 +0000
parents
children
comparison
equal deleted inserted replaced
5809:c794ed00d473 5810:34010a1e9aea
1 ## Copyright (C) 2006 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 2, or (at your option)
8 ## 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, write to the Free
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA.
19
20 ## -*- texinfo -*-
21 ## @deftypefn {Built-in Function} {} genpath (@var{dir})
22 ## Return a path constructed from @var{dir} and all its subdiretories.
23 ## @end deftypefn
24
25 function retval = genpath (dirname)
26
27 if (nargin == 1)
28 s = stat (dirname);
29 if (S_ISDIR (s.mode))
30 lst = __genpath__ (dirname);
31 lst{2,:} = pathsep ();
32 lst{2,end} = "";
33 retval = strcat (lst{:});
34 else
35 retval = "";
36 endif
37 else
38 print_usage ("genpath");
39 endif
40
41 endfunction
42
43 function retval = __genpath__ (dirname)
44
45 retval = {dirname};
46
47 s = dir (dirname);
48 n = length (s);
49 for i = 1:n
50 elt = s(i);
51 nm = elt.name;
52 if (elt.isdir && ! (strcmp (nm, ".") || strcmp (nm, "..")))
53 ## FIXME -- Octave bug: recursion fails here if the __genpath__
54 ## call is moved inside the [].
55 tmp = __genpath__ (fullfile (dirname, nm));
56 retval = [retval, tmp];
57 endif
58 endfor
59
60 endfunction