It was just an attempt to see how someone else may tackle this issue. I
thought of sorting, but I wasn't sure it will do exactly what I expect.
Here is what I've have so far:
my $dir = "/mydir";
opendir(DH, "$dir") || die "Failed to open $dir: $!\n";
my $counter = 0;
while (defined(my $file = readdir (DH))){
next if $file =~ /^\.+$/;
push @files, $file;
$counter++;
}
closedir (DH);
if ($counter > 7){
for (@files){
$file_mtime{$_} = (stat($_))[9];
Need to compare mtime here...
}
}
||-----Original Message-----
||From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
||Sent: Saturday, February 12, 2005 5:19 PM
||To: [EMAIL PROTECTED]
||Cc: [email protected]
||Subject: Re: Compare file modification time
||
||[EMAIL PROTECTED] wrote:
||> How do I best compare mtime of several files. I have a script for making
||> daily backups into a given directory. Now I want to modify it to
||> delete old backups if the total exceed cetain number.
||>
||> The idea was to compare the mtime of all file to figure out old files to
||> delete, but somehow I think it shouldn't be all that complicated.
||> Any elegant idea on how to acomplice this?
||>
||> Thanks
||>
||
||mtimes are just integers, so you can compare them with the normal math
||operators. Theoretically you can open a directory, list the files, read
||the mtimes with c<stat> into a hash with file/mtime structure. Then just
||sort the hash by the mtime, and remove any files beyond your desired
||threshold.
||
||What have you tried? Where did you fail?
||
||perldoc -f opendir
||perldoc -f readdir
||perldoc -f unlink
||perldoc -f stat
||perldoc -f sort
||
||Those 5 functions should get you started...
||
||http://danconia.org
||
||--
||To unsubscribe, e-mail: [EMAIL PROTECTED]
||For additional commands, e-mail: [EMAIL PROTECTED]
||<http://learn.perl.org/> <http://learn.perl.org/first-response>
||
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>