annotate scripts/miscellaneous/dir.m @ 20164:df437a52bcaf stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed miscellaneous, sparse, strings in scripts directory. * scripts/miscellaneous/bzip2.m, scripts/miscellaneous/citation.m, scripts/miscellaneous/compare_versions.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dir.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/error_ids.m, scripts/miscellaneous/fileattrib.m, scripts/miscellaneous/fullfile.m, scripts/miscellaneous/genvarname.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/news.m, scripts/miscellaneous/open.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/recycle.m, scripts/miscellaneous/run.m, scripts/miscellaneous/swapbytes.m, scripts/miscellaneous/tar.m, scripts/miscellaneous/tmpnam.m, scripts/miscellaneous/unpack.m, scripts/miscellaneous/what.m, scripts/sparse/bicg.m, scripts/sparse/bicgstab.m, scripts/sparse/cgs.m, scripts/sparse/colperm.m, scripts/sparse/eigs.m, scripts/sparse/etreeplot.m, scripts/sparse/gmres.m, scripts/sparse/gplot.m, scripts/sparse/ichol.m, scripts/sparse/ilu.m, scripts/sparse/pcg.m, scripts/sparse/pcr.m, scripts/sparse/qmr.m, scripts/sparse/spaugment.m, scripts/sparse/spconvert.m, scripts/sparse/spdiags.m, scripts/sparse/spfun.m, scripts/sparse/spones.m, scripts/sparse/sprandsym.m, scripts/sparse/spstats.m, scripts/sparse/spy.m, scripts/sparse/svds.m, scripts/sparse/treelayout.m, scripts/sparse/treeplot.m, scripts/strings/base2dec.m, scripts/strings/bin2dec.m, scripts/strings/blanks.m, scripts/strings/cstrcat.m, scripts/strings/deblank.m, scripts/strings/dec2base.m, scripts/strings/dec2bin.m, scripts/strings/dec2hex.m, scripts/strings/findstr.m, scripts/strings/hex2dec.m, scripts/strings/index.m, scripts/strings/isletter.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strchr.m, scripts/strings/strjoin.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/strsplit.m, scripts/strings/strtok.m, scripts/strings/strtrim.m, scripts/strings/strtrunc.m, scripts/strings/substr.m, scripts/strings/untabify.m, scripts/time/datenum.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Mon, 04 May 2015 14:22:02 -0700
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
1 ## Copyright (C) 2004-2015 John W. Eaton
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
2 ##
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
4 ##
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
dd8d08c41c0c [project @ 2004-01-11 18:20:51 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: 7007
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: 7007
diff changeset
8 ## your option) any later version.
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
9 ##
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
14 ##
dd8d08c41c0c [project @ 2004-01-11 18:20:51 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: 7007
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: 7007
diff changeset
17 ## <http://www.gnu.org/licenses/>.
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
18
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
20 ## @deftypefn {Function File} {} dir
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
21 ## @deftypefnx {Function File} {} dir (@var{directory})
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefnx {Function File} {[@var{list}] =} dir (@var{directory})
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
23 ## Display file listing for directory @var{directory}.
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
24 ##
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
25 ## If @var{directory} is not specified then list the present working directory.
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
26 ##
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
27 ## If a return value is requested, return a structure array with the fields
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
28 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
29 ## @table @asis
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
30 ## @item name
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17908
diff changeset
31 ## File or directory name.
17513
fedcd3717ebc doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents: 17397
diff changeset
32 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
33 ## @item date
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
34 ## Timestamp of file modification (string value).
17513
fedcd3717ebc doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents: 17397
diff changeset
35 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
36 ## @item bytes
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
37 ## File size in bytes.
17513
fedcd3717ebc doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents: 17397
diff changeset
38 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
39 ## @item isdir
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17908
diff changeset
40 ## True if name is a directory.
17513
fedcd3717ebc doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents: 17397
diff changeset
41 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
42 ## @item datenum
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
43 ## Timestamp of file modification as serial date number (double).
17513
fedcd3717ebc doc: grammarcheck of documentation before 3.8 release.
Rik <rik@octave.org>
parents: 17397
diff changeset
44 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
45 ## @item statinfo
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
46 ## Information structure returned from @code{stat}.
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
47 ## @end table
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
48 ##
17397
0bf2fc8562c9 doc: Update documentation for file and directory functions.
Rik <rik@octave.org>
parents: 17338
diff changeset
49 ## If @var{directory} is a filename, rather than a directory, then return
17908
7df8f5372ea8 doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents: 17744
diff changeset
50 ## information about the named file. @var{directory} may also be a list rather
7df8f5372ea8 doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents: 17744
diff changeset
51 ## than a single directory or file.
7df8f5372ea8 doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents: 17744
diff changeset
52 ##
7df8f5372ea8 doc: Add note about wildcard expansion in ls and dir functions (bug #40544).
Rik <rik@octave.org>
parents: 17744
diff changeset
53 ## @var{directory} is subject to shell expansion if it contains any wildcard
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
54 ## characters @samp{*}, @samp{?}, @samp{[]}. To find a literal example of a
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
55 ## wildcard character the wildcard must be escaped using the backslash operator
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
56 ## @samp{\}.
6955
4aef2ca14cf9 [project @ 2007-10-04 16:38:11 by jwe]
jwe
parents: 6947
diff changeset
57 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
58 ## Note that for symbolic links, @code{dir} returns information about the
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
59 ## file that the symbolic link points to rather than the link itself.
7007
6304d9ea0a30 [project @ 2007-10-11 16:26:36 by jwe]
jwe
parents: 6955
diff changeset
60 ## However, if the link points to a nonexistent file, @code{dir} returns
6955
4aef2ca14cf9 [project @ 2007-10-04 16:38:11 by jwe]
jwe
parents: 6947
diff changeset
61 ## information about the link.
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
62 ## @seealso{ls, readdir, glob, what, stat, lstat}
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
63 ## @end deftypefn
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
64
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
65 ## Author: jwe
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
66
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
67 ## FIXME: This is quite slow for large directories.
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
68 ## Perhaps it should be converted to C++?
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
69
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
70 function retval = dir (directory)
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
71
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
72 if (nargin == 0)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
73 directory = ".";
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
74 elseif (nargin > 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5775
diff changeset
75 print_usage ();
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
76 endif
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
77
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
78 if (! ischar (directory))
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
79 error ("dir: DIRECTORY argument must be a string");
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
80 endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
81
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5689
diff changeset
82 ## Prep the retval.
6947
4b41514e5ef0 [project @ 2007-10-03 14:47:32 by jwe]
jwe
parents: 6115
diff changeset
83 info = struct (zeros (0, 1),
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10262
diff changeset
84 {"name", "date", "bytes", "isdir", "datenum", "statinfo"});
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
85
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
86
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
87 if (strcmp (directory, "*"))
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
88 directory = ".";
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
89 endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
90 if (strcmp (directory, "."))
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
91 flst = {"."};
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
92 nf = 1;
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
93 else
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
94 flst = glob (directory);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
95 nf = numel (flst);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
96 endif
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
97
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
98 ## Determine the file list for the case where a single directory is specified.
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
99 if (nf == 1)
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
100 fn = flst{1};
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
101 [st, err, msg] = stat (fn);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
102 if (err < 0)
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
103 warning ("dir: 'stat (%s)' failed: %s", fn, msg);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
104 nf = 0;
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
105 elseif (S_ISDIR (st.mode))
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
106 flst = readdir (flst{1});
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
107 nf = numel (flst);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
108 for i = 1:nf
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
109 flst{i} = fullfile (fn, flst{i});
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
110 endfor
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5689
diff changeset
111 endif
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
112 endif
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
113
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
114 if (numel (flst) > 0)
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
115 ## Collect results.
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
116 for i = nf:-1:1
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
117 fn = flst{i};
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
118 [st, err, msg] = lstat (fn);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
119 if (err < 0)
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
120 warning ("dir: 'lstat (%s)' failed: %s", fn, msg);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
121 else
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
122 ## If we are looking at a link that points to something,
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
123 ## return info about the target of the link, otherwise, return
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
124 ## info about the link itself.
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
125 if (S_ISLNK (st.mode))
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
126 [xst, err, msg] = stat (fn);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
127 if (! err)
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
128 st = xst;
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
129 endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
130 endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
131 [dummy, fn, ext] = fileparts (fn);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
132 fn = [fn ext];
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
133 info(i,1).name = fn;
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
134 lt = localtime (st.mtime);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
135 info(i,1).date = strftime ("%d-%b-%Y %T", lt);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
136 info(i,1).bytes = st.size;
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
137 info(i,1).isdir = S_ISDIR (st.mode);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
138 info(i,1).datenum = datenum (lt.year + 1900, lt.mon + 1, lt.mday,
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
139 lt.hour, lt.min, lt.sec);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
140 info(i,1).statinfo = st;
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
141 endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
142 endfor
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
143 endif
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
144
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5689
diff changeset
145 ## Return the output arguments.
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
146 if (nargout > 0)
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5689
diff changeset
147 ## Return the requested structure.
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
148 retval = info;
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
149 elseif (numel (info) > 0)
5690
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5689
diff changeset
150 ## Print the structure to the screen.
161ebd1f3410 [project @ 2006-03-17 06:17:24 by jwe]
jwe
parents: 5689
diff changeset
151 printf ("%s", list_in_columns ({info.name}));
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
152 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14327
diff changeset
153 warning ("dir: nonexistent directory '%s'", directory);
5689
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
154 endif
9a16df2b1916 [project @ 2006-03-17 05:00:57 by jwe]
jwe
parents: 5642
diff changeset
155
4694
dd8d08c41c0c [project @ 2004-01-11 18:20:51 by jwe]
jwe
parents:
diff changeset
156 endfunction
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 16994
diff changeset
157
19198
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
158
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
159 %!test
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
160 %! list = dir ();
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
161 %! assert (isstruct (list) && ! isempty (list));
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
162 %! assert (fieldnames (list),
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
163 %! {"name"; "date"; "bytes"; "isdir"; "datenum"; "statinfo"});
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
164 %!
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
165 %! if (isunix ())
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
166 %! assert ({list(1:2).name}, {".", ".."});
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
167 %! assert ([list(1:2).isdir], [true true]);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
168 %! endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
169 %!
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
170 %! ## test that specifying a filename works the same as using a directory.
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
171 %! found = find (! [list.isdir], 1);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
172 %! if (! isempty (found))
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
173 %! list2 = dir (list(found).name);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
174 %! assert (list(found), list2);
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
175 %! endif
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
176
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
177 ## Test input validation
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
178 %!error <DIRECTORY argument must be a string> dir (1)
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
179 %!warning <nonexistent directory> dir ("_%UNLIKELY_DIR_NAME%_");
931cc13a6f3b Rework ls.m and dir.m
Rik <rik@octave.org>
parents: 17908
diff changeset
180