#!/usr/bin/perl $DIR1="/users/model/data/reports"; $DIR2="/users/model/data/reports/temp"; &Filter($DIR1); &Filter($DIR2); exit(0); sub Filter { local($dir) = @_; opendir(DIR,$dir); while ($file = readdir(DIR)) { next if !($file =~ /\.temp/); unlink("$file");} closedir(DIR); opendir(DIR,$dir); while ($file = readdir(DIR)) { next if !($file =~ /\.report$/ ); open (INPUT,"<$file") || die "Error Opening File. $!\n"; open (OUTPUT,">>$dir/$file.temp") || die "Error Opening File for Write. $!\n"; foreach $read(){ if ($read=~ s/'//g) { print OUTPUT "$read"; } else {print OUTPUT "$read";} } close (INPUT); close (OUTPUT); } closedir(DIR); opendir(DIR,$dir); @model_reports = readdir(DIR); closedir(DIR); for (@model_reports) { next if !($_ =~ /\.temp$/ ); $oldname = $_; $_ =~ s/.temp//; rename("$dir/$oldname","$dir/$_"); #unix } }