1 ## Copyright (C) 2006-2012 John W. Eaton
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Command} {} ls options
21 ## List directory contents. For example:
27 ## @print{} -rw-r--r-- 1 jwe users 4488 Aug 19 04:02 foo.m
28 ## @print{} -rw-r--r-- 1 jwe users 1315 Aug 17 23:14 bar.m
32 ## The @code{dir} and @code{ls} commands are implemented by calling your
33 ## system's directory listing command, so the available options may vary
34 ## from system to system.
35 ## @seealso{dir, stat, readdir, glob, filesep, ls_command}
40 function retval = ls (varargin)
42 global __ls_command__;
44 if (isempty (__ls_command__) || ! ischar (__ls_command__))
45 ## Initialize value for __ls_command__.
49 if (! iscellstr (varargin))
50 error ("ls: all arguments must be character strings");
54 args = tilde_expand (varargin);
55 if (ispc () && ! isunix ())
56 ## shell (cmd.exe) on MinGW uses '^' as escape character
57 args = regexprep (args, '([^\w.*? -])', '^$1');
59 args = regexprep (args, '([^\w.*? -])', '\$1');
61 args = sprintf ("%s ", args{:});
66 cmd = sprintf ("%s %s", __ls_command__, args);
68 if (page_screen_output () || nargout > 0)
69 [status, output] = system (cmd);
72 error ("ls: command exited abnormally with status %d\n", status);
76 retval = strvcat (regexp (output, '\S+', 'match'){:});
79 ## Just let the output flow if the pager is off. That way the
80 ## output from things like "ls -R /" will show up immediately and
81 ## we won't have to buffer all the output.
90 %! assert (ischar (list));
91 %! assert (! isempty (list));