Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read windows file attribute in Perl? 1

Status
Not open for further replies.

bmerr

Programmer
Feb 17, 2005
3
0
0
US
Hello All,

I'm trying to write a cataloging program in Perl, that will loop through a directory and gather various information about windows files. I'm trying to figure out how to read the "date created" and "date modified" on different windows files. I have googled about 100 different word combos without having found a single page that refers on how to do this. Does anyone have any info or direction on how this can be achieved?

Thank you.
 
you can use the stat() function to check file information. If all you want is: accessed, created, modified, something along these lines:

Code:
my ($last_access,$modified,$created) = (stat('path\to\file.txt'))[8,9,10];

print 'Accessed: ' . localtime($last_access) . "\n";
print 'Created: ' . localtime($created) . "\n";
print 'Modified: ' . localtime($modified) . "\n";

stat() returns a 13 element array but not all fields are supported on all filesystem types. Here they are:


Code:
0 dev      device number of filesystem
1 ino      inode number
2 mode     file mode  (type and permissions)
3 nlink    number of (hard) links to the file
4 uid      numeric user ID of file's owner
5 gid      numeric group ID of file's owner
6 rdev     the device identifier (special files only)
7 size     total size of file, in bytes
8 atime    last access time since the epoch
9 mtime    last modify time since the epoch
10 ctime    inode change time (NOT creation time!) since the epoch
11 blksize  preferred block size for file system I/O
12 blocks   actual number of blocks allocated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top