Getting Information on a File : stat « File « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » File » stat 
Getting Information on a File
    

The stat function gets a host of information about a file: 

($dev, $inode, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,$mtime, $ctime, $blksize, $blocks= stat(file);

The file can be either a file handle referring to a file you've opened or a file name. 
The stat function returns a list. 
The values returned from the stat function are listed in the following table.
The time values are returned as seconds from January 11970.
If you don't have permission to read the file, lstat and stat will return an empty list.

Value       Holds
$dev        Device number of file system.
$inode      Inode number.
$mode       File mode (type and permissions).
$nlink      Number of hard links to the file.
$uid        Numeric user ID of file's owner.
$gid        Numeric group ID of file's owner.
$rdev       The device identifier device (specialfiles only.
$size       Total size of file, in bytes.
$atime      Time of last access.
$mtime      Time of last modification.
$ctime      Time of inode change.
$blksize    Preferred block size for file system I/O.
$blocks     Actual number of blocks allocated.

   
    
    
    
  
Related examples in the same category
1.Get return value from stat function
2.Get the file size
3.Get the length of a file
4.File statistics returned from the stat command
5.File stats
6.Checks the permissions of a file
7.Call stat function from file handle
8.Lists files in directory; then gets info on files with stat
9.The stat Function for Windows NT File Attributes
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.