file()

Test for file existence and return the last modification time

Syntax

file(filename,[enhanced])

Parameters

ParameterDefinition

filename

name of the file whose last modification date is returned

enhanced

optional flag that requests additional file information in the following form: 
modtime atime ctime mode size numlinks type

  • modtime is the last modification date expressed as the number of seconds since midnight, January 1, 1970
  • atime is the last access time expressed as the number of seconds since midnight, January 1, 1970
  • ctime is the last change of status expressed as the number of seconds since midnight, January 1, 1970
  • mode is the file permissions expressed as an octal integer
  • size is the length of the file expressed as a number of characters
  • numlinks the number of links to the file within the file system
  • type is a character string indicating the file type:
    • FILE-- ordinary user data file
    • DIR-- directory
    • SPECIAL-- character special file
    • BLOCK-- block special file
    • FIFO-- pipe or FIFO
    • LINK-- symbolic link
    • SOCKET-- socket (not available on all platforms)
    • UNKNOWN-- unknown file type, possibly a LINK or SOCKET on platforms where the Unix stat() function cannot determine the type; that is, where S_ISLINK or S_ISSOCK are undefined 
      Currently, the value of 1 for the enhanced parameter is only a place holder and any value is valid, but it is recommended that you use a 1 to specify this parameter to accommodate future enhancements to this function.

Description

The file() function returns the last modification time of file filename as the number of seconds since midnight, January 1, 1970. If the file does not exist, the file() function returns the NULL string. This function is useful for testing the existence of a file.

Note

The file() function return values depend on the operating system and in some cases the file system. Some non-Unix platforms may not return all return values or may return one or more meaningless return values. For a specific platform, the file() function will generally return the same information as the C programming language stat() function.



The user does not need permission to read the file but does require search permission on each directory in the path name leading to filename. If the user does not have such permission, the file() function fails and returns the NULL string. 

When the enhanced parameter is specified, the file() function returns a more detailed string of information.

Example

The following examples highlight the usage of the file() function.

Print Last Modify Date of the Unix System Password File

print (asctime(file("/etc/passwd"))); # modification time

Test for Existence of a File and Print Enhanced Information

file_name="e:\\some_file_name.txt";
if (file(file_name)) {
print("File ",file_name," exists!");
print("\nEnhanced Information: \n",file(file_name,1));
} else {
print("File does not exist.");
}



The following is the output from the previous example:

File e:\some_file_name.txt exists!
Enhanced Information:
972340188 979711200 962992053 666 2459 1 FILE
Was this page helpful? Yes No Submitting... Thank you

Comments