Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Français


fileinfo

provide information about some files of any type

Syntax

x = fileinfo(filesPaths)
[x,ierr] = fileinfo(filesPaths)

Arguments

filesPaths

vector or matrix of paths (as text). Files of any type can be targeted: regular files, directories (in their own), shortcuts, symbolic links, etc.

x

matrix of decimal integers, of sizes (m,13) with m: number of provided files paths. The row #i returns information about the file filesPaths(i).

If only one path is queried and the file does not exist, x returns [].

If several files are queried: when a file among them does not exist, its x row is filled with Nan values.

x columnDescription
1 : actual file size (bytes). 0 for directories.
2 : file permissions (see the description)
3 : id of the file's owner (always 0 on Windows)
4 : id of the file's group (always 0 on Windows)
5 : Device number
6 : UNIX timestamp of last data modification. getdate(x(:,6))(:,[1 2 6 7 8 9]) returns the corresponding date as a matrix of [year month day hour mn ss] numerical rows.
7 : UNIX timestamp of last change of the file status.
8 : UNIX timestamp of last access to the file.
9 : The device type (if inode device).
10 : Blocksize of the I/O filesystem (always 0 on Windows)
11 : Number of blocks allocated to this file storage (always 0 on Windows)
12 : File's inode (unique id) (always 0 on Windows)
13 : Number of hard links pointing to this file (always 1 on Windows).

ierr

error flag: 0, if no error has occurred.

Description

This function is an interface to the C function stat.

Permissions are typically specified as octal numbers: dec2oct(x(2)) to convert.

Numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2, and 1. Any omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2) and sticky (1) attributes. The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the third selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values.

So, to check permissions, it is necessary to use masks. Let us take an example: In octal, x(2)=1664, so first digit corresponds to sticky attributes. The second indicates that file owner has permission of writing and reading. It is the same for other users in the file's group. Finally, others users has just right to read. To apply a mask, it is simpler to look at this octal in binary. So: x(2)= 1 110 110 100. To check if the owner has write permission, we must take a look at the second triplet: 110 and compare it with write permission 010. So, the operation is: 110 000 000 & 010 000 000. If result is not null (it is the case here), owner has write permission.

Examples

w = fileinfo(SCI+'/etc/scilab.start')
// file permission
dec2oct(w(2))
// file date:  [year month day hh mn ss .ss]
getdate(w(6))(:,[1 2 6:10])

// Permissions
S_IWRITE = 128; // mask write permission
S_IEXEC = 64; // mask exec permission
S_IREAD = 256; // mask read permission
S_IFCHR = 8192; // mask directory permission

// Checks write permission
if ( bitand( w(2), S_IWRITE ) <> 0) then
 disp('WRITE PERMISSION on this file.');
else
 disp('NO WRITE PERMISSION on this file.');
end
// Checks read permission
if ( bitand( w(2), S_IREAD ) <> 0) then
 disp('READ PERMISSION on this file.');
else
 disp('NO READ PERMISSION on this file.');
end

FILES = [SCI;SCIHOME;'not_exist_file';TMPDIR]
[X,ERRS] = fileinfo(FILES)

See also

  • getdate — Current datetime or POSIX timestamp from computer's clock. Datetimes from given timestamps
  • file — file management
  • dispfiles — displays properties of opened files
  • newest — returns newest file of a set of files
  • isfile — checks whether argument is an existing file
  • isdir — checks that a path points to an existing directory

History

VersionDescription
6.0.0 Several files paths can now be processed.
Report an issue
<< deletefile file_system findfiles >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:52:28 CEST 2024