changelog shortlog tags changeset files revisions annotate raw

scripts/miscellaneous/ls.m

changeset 10289: 4b124317dc38
parent:eb63fbe60fab
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (42 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2006, 2007, 2008, 2009 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 3 of the License, or (at
8## your option) 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, see
17## <http://www.gnu.org/licenses/>.
18
19## -*- texinfo -*-
20## @deffn {Command} ls options
21## List directory contents. For example,
22##
23## @example
24## @group
25## ls -l
26## @print{} total 12
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
29## @end group
30## @end example
31##
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}
36## @end deffn
37
38## Author: jwe
39
40function retval = ls (varargin)
41
42 global __ls_command__;
43
44 if (isempty (__ls_command__) || ! ischar (__ls_command__))
45 ## Initialize value for __ls_command__.
46 ls_command ();
47 endif
48
49 if (iscellstr (varargin))
50
51 args = tilde_expand (varargin);
52
53 cmd = sprintf ("%s ", __ls_command__, args{:});
54
55 if (page_screen_output () || nargout > 0)
56
57 [status, output] = system (cmd);
58
59 if (status == 0)
60 if (nargout == 0)
61 puts (output);
62 else
63 retval = strvcat (regexp (output, '[^\s]+', 'match'){:});
64 endif
65 else
66 error ("ls: command exited abnormally with status %d", status);
67 endif
68
69 else
70 ## Just let the output flow if the pager is off. That way the
71 ## output from things like "ls -R /" will show up immediately and
72 ## we won't have to buffer all the output.
73 system (cmd);
74 endif
75
76 else
77 error ("ls: expecting all arguments to be character strings");
78 endif
79
80endfunction
81
82%!error ls (1);
83