changelog shortlog tags changeset files revisions annotate raw

scripts/miscellaneous/fileattrib.m

changeset 10289: 4b124317dc38
parent:93c65f2a5668
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (37 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 2005, 2006, 2007 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## @deftypefn {Function File} {[@var{status}, @var{msg}, @var{msgid}] =} fileattrib (@var{file})
21## Return information about @var{file}.
22##
23## If successful, @var{status} is 1, with @var{result} containing a
24## structure with the following fields:
25##
26## @table @code
27## @item Name
28## Full name of @var{file}.
29## @item archive
30## True if @var{file} is an archive (Windows).
31## @item system
32## True if @var{file} is a system file (Windows).
33## @item hidden
34## True if @var{file} is a hidden file (Windows).
35## @item directory
36## True if @var{file} is a directory.
37## @item UserRead
38## @itemx GroupRead
39## @itemx OtherRead
40## True if the user (group; other users) has read permission for
41## @var{file}.
42## @item UserWrite
43## @itemx GroupWrite
44## @itemx OtherWrite
45## True if the user (group; other users) has write permission for
46## @var{file}.
47## @item UserExecute
48## @itemx GroupExecute
49## @itemx OtherExecute
50## True if the user (group; other users) has execute permission for
51## @var{file}.
52## @end table
53## If an attribute does not apply (i.e., archive on a Unix system) then
54## the field is set to NaN.
55##
56## With no input arguments, return information about the current
57## directory.
58##
59## If @var{file} contains globbing characters, return information about
60## all the matching files.
61## @seealso{glob}
62## @end deftypefn
63
64function [status, msg, msgid] = fileattrib (file)
65
66 status = true;
67 msg = "";
68 msgid = "";
69
70 if (nargin == 0)
71 file = ".";
72 endif
73
74 if (ischar (file))
75 files = glob (file);
76 if (isempty (files))
77 files = {file};
78 nfiles = 1;
79 else
80 nfiles = length (files);
81 endif
82 else
83 error ("fileattrib: expecting first argument to be a character string");
84 endif
85
86 if (nargin == 0 || nargin == 1)
87
88 r_n = r_a = r_s = r_h = r_d ...
89 = r_u_r = r_u_w = r_u_x ...
90 = r_g_r = r_g_w = r_g_x ...
91 = r_o_r = r_o_w = r_o_x = cell (nfiles, 1);
92
93 curr_dir = pwd ();
94
95 for i = 1:nfiles
96 [info, err, msg] = stat (files{i});
97 if (! err)
98 r_n{i} = canonicalize_file_name (files{i});
99 r_a{i} = NaN;
100 r_s{i} = NaN;
101 r_h{i} = NaN;
102 r_d{i} = S_ISDIR (info.mode);
103 ## FIXME -- maybe we should have S_IRUSR etc. masks?
104 modestr = info.modestr;
105 r_u_r{i} = modestr(2) == "r";
106 r_u_w{i} = modestr(3) == "w";
107 r_u_x{i} = modestr(4) == "x";
108 r_g_r{i} = modestr(5) == "r";
109 r_g_w{i} = modestr(6) == "w";
110 r_g_x{i} = modestr(7) == "x";
111 r_o_r{i} = modestr(8) == "r";
112 r_o_w{i} = modestr(9) == "w";
113 r_o_x{i} = modestr(10) == "x";
114 else
115 status = false;
116 msgid = "fileattrib";
117 break;
118 endif
119 endfor
120 if (status)
121 r = struct ("Name", r_n, "archive", r_a, "system", r_s,
122 "hidden", r_s, "directory", r_d, "UserRead", r_u_r,
123 "UserWrite", r_u_w, "UserExecute", r_u_x,
124 "GroupRead", r_g_r, "GroupWrite", r_g_w,
125 "GroupExecute", r_g_x, "OtherRead", r_o_r,
126 "OtherWrite", r_o_w, "OtherExecute", r_o_x);
127 if (nargout == 0)
128 status = r;
129 else
130 msg = r;
131 endif
132 endif
133 else
134 print_usage ();
135 endif
136
137endfunction