1 <?xml version="1.0" encoding="UTF-8"?>
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) XXXX-2008 - INRIA
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="fileinfo" xml:lang="en">
15 <refname>fileinfo</refname>
16 <refpurpose>provides information about a file</refpurpose>
19 <title>Calling Sequence</title>
20 <synopsis>[x, ierr] = fileinfo(files)</synopsis>
23 <title>Arguments</title>
28 <para>a character string or a string column vector, file
36 <para>an integer vector of size 13 containing information or an
37 empty matrix if file does not exist.
40 If <varname>files</varname> is a string column vector, <varname>x</varname> will be a matrix of
41 size <literal>m x 13</literal>.
44 If a filename does not exist, it will return as output
45 information a line of size 13 with <constant>Nan</constant>
46 in each element of this line.
53 <para>error indicator, 0, if no error has occurred.</para>
59 <title>Description</title>
61 <code>x = fileinfo(file)</code> returns:
67 <para>The file size</para>
73 <para>The file mode (decimal value)</para>
79 <para>The user id</para>
85 <para>The group id</para>
91 <para>The device number</para>
97 <para>The date of last data modification</para>
103 <para>The date of last file status change</para>
109 <para>The date of last access</para>
115 <para>The device type (if inode device)</para>
121 <para>The blocksize for filesystem I/O (always 0 on Windows)</para>
127 <para>The number of blocks allocated (always 0 on Windows)</para>
133 <para>The inode</para>
139 <para>The number of hard links</para>
145 <title>References</title>
147 This function is an interface to the C function <function>stat</function>.
150 Permissions are typically specified as octal numbers: <code>dec2oct(x(2))</code> to convert.
152 <para>Numeric mode is from one to four octal digits (0-7), derived by
153 adding up the bits with values 4, 2, and 1. Any omitted digits are assumed
154 to be leading zeros. The first digit selects the set user ID (4) and set
155 group ID (2) and sticky (1) attributes. The second digit selects
156 permissions for the user who owns the file: read (4), write (2), and
157 execute (1); the third selects permissions for other users in the file's
158 group, with the same values; and the fourth for other users not in the
159 file's group, with the same values.
162 So, to check permissions, it is necessary to use masks. Let us take an example:
163 In octal, x(2)=1664, so first digit corresponds to sticky attributes. The second
164 indicates that file owner has permission of writing and reading. It is the same
165 for other users in the file's group. Finally, others users has just right to read.
166 To apply a mask, it is simpler to look at this octal in binary.
167 So: <varname>x</varname>(2)= 1 110 110 100.
168 To check if the owner has write permission, we must take a look at the second triplet: 110
169 and compare it with write permission 010. So, the operation is: 110 000 000 & 010 000 000.
170 If result is not null (it is the case here), owner has write permission.
174 <title>Examples</title>
175 <programlisting role="example"><![CDATA[
176 w = fileinfo(SCI+'/etc/scilab.start')
183 S_IWRITE = 128; // mask write permission
184 S_IEXEC = 64; // mask exec permission
185 S_IREAD = 256; // mask read permission
186 S_IFCHR = 8192; // mask directory permission
188 // Checks write permission
189 if ( bitand( w(2), S_IWRITE ) <> 0) then
190 disp('WRITE PERMISSION on this file.');
192 disp('NO WRITE PERMISSION on this file.');
194 // Checks read permission
195 if ( bitand( w(2), S_IREAD ) <> 0) then
196 disp('READ PERMISSION on this file.');
198 disp('NO READ PERMISSION on this file.');
201 FILES = [SCI;SCIHOME;'not_exist_file';TMPDIR]
202 [X,ERRS] = fileinfo(FILES)
205 <refsection role="see also">
206 <title>See Also</title>
207 <simplelist type="inline">
209 <link linkend="getdate">getdate</link>
212 <link linkend="file">file</link>
215 <link linkend="dispfiles">dispfiles</link>
218 <link linkend="newest">newest</link>
221 <link linkend="isdir">isdir</link>