in reply to removing files with perl based on age and name

From what I can understand from your post, you need a bac file and its creation date.
Next you need to delete all the files which are older than that bac file and those whose names do not match with that bac file.

So try this code if it works for you.

Pass bac file name as an argument.

Example:
perl test.pl 000000010000000300000067.00000020.bac
use v5.14; my $bacFileName = $ARGV[0]; #First get the epoch creation time of bac file my $bacFileTime = `stat $bacFileName --format=%W`; foreach my $fileName (`ls`) { chomp($fileName); next if $fileName eq $bacFileName; my $bacTypeFileName = ( ( split /\./, $bacFileName )[0] ); next if $fileName =~ /$bacTypeFileName/; my $fileCreationTime = `stat $fileName --format=%W`; next if $fileCreationTime > $bacFileTime; `rm -rf $fileName`; }

Replies are listed 'Best First'.
Re^2: removing files with perl based on age and name
by hippo (Archbishop) on Jul 18, 2014 at 11:31 UTC

    Why shell out to stat instead of using the builtin? Why the -r and -f on the rm when you are only deleting one file at a time? Why use backticks for the rm? Why shell out to rm at all when we have unlink?

    As it stands your script looks a bit too dangerous to consider running, sorry.

    A reply falls below the community's threshold of quality. You may see it by logging in.