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

Change language to:
English - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Aide de Scilab >> Entrées/Sorties [fichiers] > fileinfo

fileinfo

provides information about a file

Syntax

[x, ierr] = fileinfo(files)

Arguments

files

a character string or a string vector, file pathname.

x

an integer vector of size 13 containing information or an empty matrix if file does not exist.

If files is a string 1 x m or m x 1 vector, x will be a matrix of size m x 13.

If a filename does not exist, it will return as output information a line of size 13 with Nan in each element of this line.

ierr

error indicator, 0, if no error has occurred.

Description

x = fileinfo(file) returns:

x(1)

The file size

x(2)

The file mode (decimal value)

x(3)

The user id

x(4)

The group id

x(5)

The device number

x(6)

The date of last data modification

x(7)

The date of last file status change

x(8)

The date of last access

x(9)

The device type (if inode device)

x(10)

The blocksize for filesystem I/O (always 0 on Windows)

x(11)

The number of blocks allocated (always 0 on Windows)

x(12)

The inode

x(13)

The number of hard links

References

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
getdate(w(6))

// 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 — renvoie la date et l'heure
  • file — file management
  • dispfiles — displays opened files properties
  • newest — returns newest file of a set of files
  • isdir — checks if argument is a directory path

History

VersionDescription
6.0.0 files can now be a row vector.
Report an issue
<< dispfiles Entrées/Sorties [fichiers] 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:
Tue Feb 14 15:06:37 CET 2017