in reply to Re: Syntax Error deleting files and folders in a directory
in thread Syntax Error deleting files and folders in a directory
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Syntax Error deleting files and folders in a directory
by GrandFather (Saint) on Dec 29, 2013 at 00:50 UTC | |
by smturner1 (Sexton) on Dec 30, 2013 at 04:16 UTC |