[tpm] Another Regex question

Chris Jones cj at enersave.ca
Tue Oct 23 07:57:18 PDT 2012


Thank you so much for all your help!
I must make a donation to something in compensation for making my 
work life more productive!

I have a bunch of files to delete in sub-directories.

I only want to keep files with the following pattern:
SomeFIle-Name.inp
SomeFIle-Name.pd2

Any other files should be deleted.  Unfortunately my simple search 
did not separate files such as:
SomeFIle-Name.r2.inp
SomeFIle-Name.r2.pd2
SimFile-Name.r2 - Baseline Design.inp

#!/usr/local/bin/perl
use strict;
use File::Find;

$\="\n";
$,="\n";

my $start=("./");

finddepth (\&wanted, $start);
sub wanted {
         my $file = $_;
         #mod, eux, cfg test for each one
         if (( -f $file) && ( $file =~ /\.(inp|pd2)$/ ))
         {
                 print "File $file, keep\n";
                 }
                 else
                 {
                         print "File $file, delete\n";
                 }
}







 >>
Christopher Jones, P.Eng.
Suite 1801, 1 Yonge Street
Toronto, ON M5E1W7
Tel. 416-203-7465
Fax. 416-946-1005
email cj at enersave.ca



More information about the toronto-pm mailing list