I am creating a new Perl script to handle a web code deploy. In the following snippet of code I am trying to remove all of the files and folders in a specified directory. EPIC is saying that I have a syntax error on the 'sub selective_delete {' line. I have no idea why. Additionally, since I am new if you could look at the code to see if it is an efficient way to perform what I am trying to do or let me know if it will or will not work I would appreciate it. My goal is to create clean efficient code.
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 $deleletes ); #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 Syntax Error deleting files and folders in a directory by smturner1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |