Getting size, date, time, type and permissions info on a file or directoryΒΆ

fileinfo()

Get size, date, time, type and permissions info about a file or directory


SYNTAX

fileinfo(pathname, size, date_created, date_accessed, date_updated[, mode])

Retrieves size, date, time, type, state and permissions information about the file or directory specified in pathname.

The following information is stored in the fields supplied as the last four arguments:

size

The file size in bytes

date_created

The date and time the file was created

date_accessed

The date and time the file was last accessed

date_updated

The date and time the file was last updated

mode

This optional argument returns the file type and permissions.

File type and permission values are stored in the standard include file $SCULPTOR/include/files.h, with the prefix FILEINFO_ (types) or PERMS_ (modes).

Types

FILEINFO_TYPE

File typemask

FILEINFO_ISFIFO

Pipe

FILEINFO_ISCHR

Characterspecial file

FILEINFO_ISDIR

Directory

FILEINFO_ISBLK

Block special file (Unix)

FILEINFO_ISREG

Regular file


Modes

PERMS_RDOWNER

Read permission for owner

PERMS_WROWNER

Write permission for owner

PERMS_EXOWNER

Execute permission for owner

PERMS_RDGROUP

Read permission for group

PERMS_WRGROUP

Write permission for group

PERMS_EXGROUP

Execute permission for group

PERMS_RDOTHER

Read permission for others

PERMS_WROTHER

Write permission for others

PERMS_EXOTHER

Execute permission for others

File type is a 4-bit value that must be masked before being tested. For example, to test whether the file is a directory, use the form:

if (mode & FILEINFO_TYPE == FILEINFO\_ISDIR)

Permission flags are individual bits. So to test for owner write permission, use the form:

if (mode & PERMS_WROWNER)

The three date/time fields should have the logical type td. See Logical types.

On UNIX systems the local time is returned, but MS-DOS and Windows return GMT.

The function returns zero if successful; otherwise it returns -1 and assigns the operating system error code to sys.Errno.


Note

On DOS/Windows, all permission types except RDOWNER, WROWNER and EXOWNER are ignored.


EXAMPLE

!temp Size,,i4
!temp DateCreated,,i4/td
!temp DateAccessed,,i4/td
!temp DateUpdated,,i4/td
!temp Mode,,i4

     fileinfo("/data/control", tmp.Size, tmp.DateCreated, tmp.DateAccessed, tmp.DateUpdated, Mode)

RELATED TOPICS

File and directory handling functions

access()

chmod()

Logical types