NAME
File::Maintenance - Maintain files based on their age.
VERSION
Version 0.02
SYNOPSIS
This module allows you to purge files from a directory based on age
use File::Maintenance;
my $fm = File::Maintenance->new({
directory => '/tmp',
pattern => '*.sess',
age => '5d', #older than five days
});
$fm->test(1); # don't execute the purge
$fm->purge; # prints the action to STDOUT but doesn't purge files
$fm->test(0); # It's all for real
$fm->purge; # Will delete old *.sess files from /tmp
$fm->recurse(1);
$fm->purge; # Will delete old *.sess files from /tmp and sub-directories
You can also archive files (move to another directory) based on age as well
use File::Maintenance;
my $fm = File::Maintenance->new({
directory => '/my/data/files',
archive_directory => '/my/archive/files'
pattern => '*',
recurse => 1, # subdirectories too
age => '30m' # older than 30 minutes
});
$fm->archive;
Each value passed to the constructor has a corresponding method for setting the value, so the archive above could have been written as:
use File::Maintenance;
my $fm = File::Maintenance->new();
$fm->directory('/my/data/files');
$fm->archive_directory('/my/archive/files);
$fm->pattern('*');
$fm->recurse(1);
$fm->age('30m);
$fm->archive;
METHODS
directory
The root directory for purging
$fm->directory('/tmp');
pattern
The pattern mask for files to process
$fm->pattern('backup*.tar.gz');
By default, the pattern is a glob. To use a regular expression, it must be quoted with the qr operator:
$fm->pattern(qr/^(foo|bar)\d\d\.jpg$/);
archive_directory
The directory that files will be archived to. If the recurse attribute is set, the archive directory hierarchy will match the source directory hierarchy
age
Files older than the age will either be archived or purged, depending on the requested action. The age can be specified by s, m, h or d - (seconds, minutes, hours or days)
$fm->age('1d'); # Files older than 1 day
$fm->age('4h'); # Files older than 4 hours
recurse
Whether to traverse subdirectories
purge
Delete files older than age
archive
Archive files older than age
get_files
Return an array of files that match the filter criteria. This method is used internally, but is useful enough to be offered externally
AUTHOR
Dan Horne, <dhorne at cpan.org>
BUGS
Please report any bugs or feature requests to bug-file-purge at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Maintenance. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc File::Maintenance
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2008 Dan Horne, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.