For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2006 > file access dates









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author file access dates
wellercs@gmail.com

2006-02-27, 6:58 pm

Hi, I am new to perl, and I want to search a root directory and find
files that have not been accessed within the last 6 months. I have
found that the stat function returns an array of file info. Could
someone please tell me which element the last accessed date is? Also
if there is a better way than using stat, please point me in the right
direction.

Thanks in advance,
Chris

Paul Lalli

2006-02-27, 6:58 pm

wellercs@gmail.com wrote:
> Hi, I am new to perl, and I want to search a root directory and find
> files that have not been accessed within the last 6 months. I have
> found that the stat function returns an array of file info. Could
> someone please tell me which element the last accessed date is?


Yes, the authors of the documentation can tell you that.
stat Returns a 13-element list giving the status info for
a file,
<snip>
Not all fields are supported on all filesystem
types. Here are the meanings of the fields:

<snip>
8 atime last access time in seconds since the epoch
<snip>



> Also
> if there is a better way than using stat, please point me in the right
> direction.


Again, please check the documenation for the function you're using,
before asking thousands of people around the world to read it to you:
The File::stat module provides a convenient, by-name
access mechanism:

use File::stat;
$sb = stat($filename);
printf "File is %s, size is %s, perm %04o, mtime
%s\n",
$filename, $sb->size, $sb->mode & 07777,
scalar localtime $sb->mtime;


Paul Lalli

usenet@DavidFilmer.com

2006-02-27, 6:58 pm

Paul Lalli wrote:
> 8 atime last access time in seconds since the epoch


Also, be warned that atime is not always what you expect. If you have
backups running, those will access the file (and modify the atime). If
you copy a file, it will modify the atime.

--
http://DavidFilmer.com

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com