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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get file creation time

Status
Not open for further replies.

varakal

IS-IT--Management
Mar 18, 2004
114
US
I have couple of questions:
1) How do we know when a file is created. In stat, atime gives the last access time and mtime gives the last modified time. But is there a way to know when the file is first created.

2) I feel this is something more difficult, is there a direct way to find when a file got deleted with in the past 5 minutes.

Thanks.
 
both points 1 and 2 are possible, but you'd need to be monitoring the directory on a full time basis to work

Code:
open FH, "<last_directory_read";
@oldfiles=<FH>';
close FH;
DIR=opendir "$directory";
@thisfiles=readdir DIR;
closedir DIR;
foreach (@oldfiles) {
   #check to see if $_ exists in @thisfiles
   #if not, then it's been deleted, so log accordingly
}
foreach (@thisfiles) {
   #check to see if $_ exists in @oldfiles
   #if not, then it's been created, so log accordingly
   open FH, ">last_directory_read";
   print FH "$_\n";
}

[code]

HTH
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top