8920
|
1 ## Copyright (C) 2006, 2007, 2008, 2009 John W. Eaton |
6115
|
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. |
6115
|
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/>. |
6115
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deffn {Command} ls options |
|
21 ## List directory contents. For example, |
|
22 ## |
|
23 ## @example |
|
24 ## ls -l |
|
25 ## @print{} total 12 |
|
26 ## @print{} -rw-r--r-- 1 jwe users 4488 Aug 19 04:02 foo.m |
|
27 ## @print{} -rw-r--r-- 1 jwe users 1315 Aug 17 23:14 bar.m |
|
28 ## @end example |
|
29 ## |
|
30 ## The @code{dir} and @code{ls} commands are implemented by calling your |
|
31 ## system's directory listing command, so the available options may vary |
|
32 ## from system to system. |
|
33 ## @seealso{dir, stat, readdir, glob, filesep, ls_command} |
|
34 ## @end deffn |
|
35 |
|
36 ## Author: jwe |
|
37 |
|
38 function retval = ls (varargin) |
|
39 |
|
40 global __ls_command__; |
|
41 |
|
42 if (isempty (__ls_command__) || ! ischar (__ls_command__)) |
|
43 ## Initialize value for __ls_command__. |
|
44 ls_command (); |
|
45 endif |
|
46 |
|
47 if (iscellstr (varargin)) |
|
48 |
|
49 args = tilde_expand (varargin); |
|
50 |
|
51 cmd = sprintf ("%s ", __ls_command__, args{:}); |
|
52 |
6943
|
53 if (page_screen_output () || nargout > 0) |
6115
|
54 |
|
55 [status, output] = system (cmd); |
|
56 |
|
57 if (status == 0) |
6943
|
58 if (nargout == 0) |
|
59 puts (output); |
|
60 else |
|
61 retval = strvcat (regexp (output, '[^\s]+', 'match'){:}); |
|
62 endif |
6115
|
63 else |
|
64 error ("ls: command exited abnormally with status %d", status); |
|
65 endif |
|
66 |
|
67 else |
|
68 ## Just let the output flow if the pager is off. That way the |
|
69 ## output from things like "ls -R /" will show up immediately and |
|
70 ## we won't have to buffer all the output. |
|
71 system (cmd); |
|
72 endif |
|
73 |
|
74 else |
|
75 error ("ls: expecting all arguments to be character strings"); |
|
76 endif |
|
77 |
|
78 endfunction |
7411
|
79 |
|
80 %!error ls (1); |
|
81 |