On Sat, 6 Jan 2001, Brian Gibson wrote:

> I am setting up an FTP Server and I am working on a script
> that will remove all files in tmp that haven't been Modified in the past
> 30 days  (for house cleaning purposes)
> 
> I found this code in O'Reilly's "Learning Perl on Win32 Systems"
> 
> ----------------------------------------------------------------------------------
> open (FILETOCHECK, "c:/test.txt");
>      if (-M FILETOCHECK > 30.0)   {
>             
>             die "Sorry, the file is older than 30 days\n";
>      }
> 
> close FILETOCHECK;
> -----------------------------------------------------------------------------------
> 
> Is it inefficient to open every file???  What if it encounters
> a 200 MB email log file, will it choke when trying to open it?
> I guess what I am saying is that when you use the open command
> does it literally load the file completely into memory?
> 
> I found a way to use the Date::Calc  module along with the stat
> function to do this (which avoids using "open") but it is quite a few more
> steps.
> 
> Any help would be greatly appreciated.
> 
> Also, I am using the system function with the DIR /S /B
> to build a list of all the files in the tmp partition, is there a perl function
> that does this a little cleaner?
> 

If all you want to check is whether or not a file has not been modified in
the last thirty days you really don't need the Date::Calc module.  All you
need to check is whether the files modified timestamp (i.e.
( (stat($file))[9] ) is less than time-30*24*3600, i.e.  the current time
minus 30 days of seconds. All the -M attribute does is subtract the
timestamp of when your perl script started from the file's modified
timestamp and convert the result into days, i.e. divide the result of
the subtraction by 24*3600 (24 hours in a day, 3600 seconds in an hour). 

**** [EMAIL PROTECTED] <Carl Jolley>
**** All opinions are my own and not necessarily those of my employer ****



_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to