-
1
- #1
Morning,
I am trying to use perl to delete old files in different folder files. I was able to do this but only for one folder. I am trying to have the perl to go and find the files in 1 folder delete and then go to another folder and then delete the files. When running the perl script it appears to find the fils okay but deletes only in the 2nd folder. Did I end something wrong?
Thanks in advance.
#!/usr/bin/perl
use File::Copy;
## CLEAN-UP FOR TS214IB
$dir_TS214IB = "/ISD-EDI/TS214IB";
$retention_period_TS214IB = "15";
## OPEN AND READ THE DIRECTORY
opendir (DIR, "$dir_TS214IB/");
@FILES = grep(/a*.*/,readdir(DIR));
closedir (DIR);
## DELETE THE .EDI FILES THAT ARE OLDER THAN X NBR OF DAYS
foreach $FILES (@FILES)
{
if (-M "$dir_TS214IB/$FILES" > $retention_period_TS214IB)
{
print "$FILES\n";
unlink("$dir_TS214IB_BK/$FILES");
}
}
## CLEAN-UP FOR TS214IB-BK
$dir_TS214IB_BK = "/ISD-EDI/TS214IB-BK";
$retention_period_TS214IB_BK = "15";
## OPEN AND READ THE DIRECTORY
opendir (DIR, "$dir_TS214IB_BK/");
@FILES = grep(/bk*.*/,readdir(DIR));
closedir (DIR);
## DELETE THE .EDI FILES THAT ARE OLDER THAN X NBR OF DAYS
foreach $FILES (@FILES)
{
if (-M "$dir_TS214IB_BK/$FILES" > $retention_period_TS214IB_BK)
{
print "$FILES\n";
unlink("$dir_TS214IB_BK/$FILES");
}
}
I am trying to use perl to delete old files in different folder files. I was able to do this but only for one folder. I am trying to have the perl to go and find the files in 1 folder delete and then go to another folder and then delete the files. When running the perl script it appears to find the fils okay but deletes only in the 2nd folder. Did I end something wrong?
Thanks in advance.
#!/usr/bin/perl
use File::Copy;
## CLEAN-UP FOR TS214IB
$dir_TS214IB = "/ISD-EDI/TS214IB";
$retention_period_TS214IB = "15";
## OPEN AND READ THE DIRECTORY
opendir (DIR, "$dir_TS214IB/");
@FILES = grep(/a*.*/,readdir(DIR));
closedir (DIR);
## DELETE THE .EDI FILES THAT ARE OLDER THAN X NBR OF DAYS
foreach $FILES (@FILES)
{
if (-M "$dir_TS214IB/$FILES" > $retention_period_TS214IB)
{
print "$FILES\n";
unlink("$dir_TS214IB_BK/$FILES");
}
}
## CLEAN-UP FOR TS214IB-BK
$dir_TS214IB_BK = "/ISD-EDI/TS214IB-BK";
$retention_period_TS214IB_BK = "15";
## OPEN AND READ THE DIRECTORY
opendir (DIR, "$dir_TS214IB_BK/");
@FILES = grep(/bk*.*/,readdir(DIR));
closedir (DIR);
## DELETE THE .EDI FILES THAT ARE OLDER THAN X NBR OF DAYS
foreach $FILES (@FILES)
{
if (-M "$dir_TS214IB_BK/$FILES" > $retention_period_TS214IB_BK)
{
print "$FILES\n";
unlink("$dir_TS214IB_BK/$FILES");
}
}