I'm trying to delete a certain set of directories using
use File::Remove qw(remove);
remove \1, "dir";
The way the script is setup is to delete all but the 5 oldest. The problem seems to be that its deleting all the directories includign the 5 I don't want deleted. Does anyone have any insight as to why it is deleting everything instead of the directories I'm trying to specify? This is on a Windows system. Thanks
Here is my code...
use strict;
use warnings;
use Mail::Sendmail;
use File::Remove qw(remove);
main();
sub main{
my $project = 'crm';
my $purgecnt = 0;
my @dirlist = '';
my $OUT = "out.txt";
# generate directoy listing of builds
#
print "\nGenerating directory output to $OUT...\n";
system("dir /b C:\\builds\\Vnet\\$project\\ > $OUT");
print "\n";
open( FP, "$OUT" ) or die "Can't open $OUT file for reading.\n";
while(my $line = <FP> ){
next if ($line =~ /^\s*$/); # blank lines
push (@dirlist, $line);
}
close FP;
#remove last 5 builds from the purge list
for(my $i=0; $i < 5; $i++){
chomp (my $temp = pop @dirlist);
if ($temp){
print "Skippping: $temp\n";
}
}
my $ra_dirlist = \@dirlist;
#print "directories to delete @$ra_dirlist\n";
# purge each item in dirlist
#
print "\n";
foreach my $item (@dirlist){
my $tree = "C:\\builds\\Vnet\\$project\\$item";
if($item eq $dirlist[-1]){
print "Purging: $item\n";
remove \1, $tree;
last;
}
$purgecnt++;
print "Purging: $item\n";
remove \1, $tree;
}
print "\n";
print "\nDone: Purged $purgecnt directories\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.