Filinfo

filinfo returns the properties of a file located on a file system that is accessible by the X3 engine. The file path is given as argument, and a second numeric argument defines the returned properties.

On UNIX, the filinfo performs a stat function on the file.

Syntax

 filinfo(FILE_PATH,INTEGER_EXPR)

Examples

### Example 1: Check the size (in bytes) of a file#### If the result is negative, the file doesn't exist or is not accessibleFILE_SIZE = filinfo(FILE_PATH, 7)### Example 2: What is the type of the UNIX MYFILE file ?#### The P1, P2, PDIR, PCAR, PBLO, PFI1, PFI2, PFIF value might depend on the version of UNIX#### check in mknod (2) documentationP1 = 2 ^ 12 : P2 = 16PFIF = 1 : PCAR = 2 : PDIR = 4 : PBLO = 6 : PFI1 = 0 : PFI2 = 8FILE_MODE = filinfo(FICHIER, 0)If FILE_MODE > 0Case int(mod(FILE_MODE/P1, P2))When PFIF : FILE_TYPE="fifo"When PCAR : FILE_TYPE="character device"When PDIR : FILE_TYPE="directory"When PBLO : FILE_TYPE="block device"When PFI1, PFI2 : FILE_TYPE="normal file"When default :FILE_TYPE="unknown"EndcaseElseFILE_TYPE="(cannot be read)"Endif### Example 3: two files xx.c and xx.o are present in the current directory#### If the xx.c file is most recent than xx.o, let's recompile itLocal Char TRACE_ERR(80)(1..24)## Check the datesIf filinfo("xx.c", 9) > filinfo("xx.o", 9)System "cc -c xx.c -o xx.o 2>trace.com"# Is the logfile empty?If filinfo("trace.com", 7)ERROR_FOUND=1ElseERROR_FOUND=0EndifEndif## A file will be modified only if the number of links is 1NB_LINKS = filinfo(DIRECTORY+"/"+FILE_NAME,4)If NB_LINKS<0 : ERROR_MSG="File does not exist"Elsif NB_LIENS >1: ERROR_MSG="File with several links"ElseOpenio DIRECTORY+"/"+FILE_NAME...Endif

Description

filinforeturns the properties of a file in a file system as the unix function stat (2) does. Depending on the second argument given, a different property is returned, according to the following table:

Second argumentPropertyAvailable on UNIXAvailable on Windows
0File mode (type, permissions)yesyes
1Inode numberyesno
2Id of the device on which the file is locatedyesno
3Id of the device if the file is a deviceyesno
4Number of linksyes1 is returned
5User ID of the owner of the fileyesyes
6Group ID of the owner of the fileyesyes
7File size in bytesyesyes
8Last access time in millisecond since 1970,1,1yesyes
9Last modification time in millisecond since 1970,1,1yes*
10Last status change time in millisecond since 1970,1,1yes*

(*) On Windows, the value returned for second arguments 9 and 10 (above) is the last access time.

Comments

filinfo returns an Integer.

If the file does not exist or cannot be accessed, a negative value that corresponds to the error status returned by the operating system is rendered. The usual values are the following:

Error valueDescription
-20File does not exist.
-27Access to the directory is denied.

Associated errors

Error codeDescription
10Incorrect argument type.
50The second argument is not in the [0,10] range.

See also

filpath, Openi, Openo, Openio