I am able to read a directory and then search files for a string match. When I find the string I want to write that file to a new file or rename and then copy to another directory the file. I can find the string but I can't stop there and do the rename/copy/delete. I'm not long in working with PERL so any help would be great. if the code does not make sence it might be because i have been trying many, many things.
Thanks for any help.
#! ./perl
use IO::File;
use File::Copy;
use File::Find;
## Open the directory
opendir(DIR,"C:\\watchin") or die "Can not open the input Directory!";
@files = grep(/\.dat$/,readdir(DIR));
closedir(DIR);
####### Now we read the files.
foreach $files (@files) {
$myfile = $files;
$report1 = 'AG Purchases Report';
open(FILE,"<C:\\Watchin\\$myfile") or die "Can't open the file darn-it \n";
open(outfile,">c:\\watchout\\AGPurchase.txt" )or die "Can't open the output file!";
@file = <FILE>;
chomp @file;
@match = grep(/AG Purchases Report/,@file);
print "@match \n";
if (@match) {
rename $myfile, AGPurchase.txt;
copy ("AGPurchase.txt", "c:\\watchout\\AGPurchase.txt");
}
print (outfile "%%EOF\n");
close FILE;
}
__END__
Thanks for any help.
#! ./perl
use IO::File;
use File::Copy;
use File::Find;
## Open the directory
opendir(DIR,"C:\\watchin") or die "Can not open the input Directory!";
@files = grep(/\.dat$/,readdir(DIR));
closedir(DIR);
####### Now we read the files.
foreach $files (@files) {
$myfile = $files;
$report1 = 'AG Purchases Report';
open(FILE,"<C:\\Watchin\\$myfile") or die "Can't open the file darn-it \n";
open(outfile,">c:\\watchout\\AGPurchase.txt" )or die "Can't open the output file!";
@file = <FILE>;
chomp @file;
@match = grep(/AG Purchases Report/,@file);
print "@match \n";
if (@match) {
rename $myfile, AGPurchase.txt;
copy ("AGPurchase.txt", "c:\\watchout\\AGPurchase.txt");
}
print (outfile "%%EOF\n");
close FILE;
}
__END__