my $prefix = shift;
my @dates;
+if ($prefix)
+{
+ $prefix = "${prefix}-";
+}
+else
+{
+ $prefix = "(?:.*-)?";
+}
+
for my $day (0 .. $days - 1)
{
push(@dates, sprintf("%04d-%02d-%02d", Subtract_Delta_Days(Today(), $day)));
}
my $dates = join("|", @dates);
-my $match = qr/^${prefix}-\d{4}-\d{2}-\d{2}\./;
-my $keep = qr/^${prefix}-(?:${dates})\./;
+my $match = qr/^\Q${prefix}\E\d{4}-\d{2}-\d{2}\./;
+my $keep = qr/^\Q${prefix}\E(?:${dates})\./;
opendir(DIR, "$dir") || die "Can't open ${dir}: $!";
-while (my $file = readdir(DIR))
-{
-# print "Expiring $file\n" if $file =~ $match && $file !~ $keep;
- unlink("${dir}/${file}") if $file =~ $match && $file !~ $keep;
-}
+my @files = sort(grep(/$match/, readdir(DIR)));
closedir(DIR);
+pop @files;
+
+for my $file (@files)
+{
+# print "Expiring $file\n" if $file !~ $keep;
+ unlink("${dir}/${file}") if $file !~ $keep;
+}
+
exit 0;
sub Monday