![](/WDVL/Website/Design/images/spacer.gif) |
Getting Information About a File With stat
Getting Information About a File With stat
- The stat function produces useful information about files
that you can use in your file management functions. The
stat function returns a thirteen-element array of file
information using the syntax:
open ([FILE_HANDLE_NAME], "[filename]")||
&CgiDie ("Can't open file");
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) =
stat([FILE_HANDLE_NAME]);
close ([FILE_HANDLE_NAME]);
- The following table describes the
elements returned by stat
Variable |
Description |
$dev |
The device that the file resides on |
$ino |
The inode for this file |
$mode |
The permissions for the file |
$nlink |
The number of hard links to the file |
$uid |
The numerical user ID for the file owner |
$gid |
The numerical group ID for the file owner |
$rdev |
The device type if the file is a device |
$size |
The size of the file in bytes |
$atime |
When the file was last accessed |
$mtime |
When the file was last modified |
$ctime |
When the file status was last changed |
$blksize |
The optimal block size for i/o operations on the file system
containing the file |
$blocks |
The number of clocks allocated to the file |
If you are interested in what the actual day is,
and not the number of seconds since 1970, you must
use the localtime function to convert the value to a
more human-recognizable form using the syntax:
($sec, $min, $hour, $mday, $mon, $year,
$wday, $yday, $isdst) = localtime (time); |
- The following code gets the same information for an
$mtime value extracted from stat:
($sec, $min, $hour, $mday, $mon, $year,
$wday, $yday, $isdst) = localtime ($mtime);
Additional Resources:
File Tests
Table of Contents
Opening, Reading and Closing Directories
| ![](/WDVL/Website/Design/images/spacer.gif) |
|