Thank you for your input. I corrected all of the bullet points you suggested with one exception; my @files is declared twice because I want to copy files and directories from the $destinationDir to the $deletes var. Can I do this with only one of the methods @files?
use strict; use warnings; use autodie; use File::Path qw(make_path rmtree); #Set vars my $destinationDir = 'C:\Users\Shaun\Documents\$website'; my $file; #Set File/Folders to exclude from delete my @KEEP = ( 'Prg421 pdf', ); #Set routine to do selective delete sub selective_delete { opendir my ($deletes), $destinationDir; #Set params my @files = glob( "$deletes/*" ); my @files = ( readdir $deletes ); #loop through directory copying all files and folders to $del for dele +tion FILE: while (my$file = @files) { for my $kp (@KEEP) { next FILE if $file eq $kp; } rmtree($deletes); } return; }
In reply to Re^2: Syntax Error deleting files and folders in a directory
by smturner1
in thread Syntax Error deleting files and folders in a directory
by smturner1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |