in reply to delete folder and its content with plain perl

My path is still having problems. I am trying to delete archive log, when I do this - system ('rmdir /S /Q "D:\log_script\Archive\2017-10-14.zip"'); directory is invalid do this - system ('rmdir /S /Q "D:/log_script/Archive/2017-10-14.zip"'); system cannot find the path do this -
my $DIR = "D:/log_script/Archive"; my @files = glob("$DIR/*.zip"); for my $file (@files) { next unless -f $file; my $age = -M $file; if ($age > 1 ) { print "$file \n"; system ( 'rmdir', '/S', '/Q', "$file"); } }
invalid switch - "log_script" anyone have idea?

Replies are listed 'Best First'.
Re^2: delete folder and its content with plain perl
by haukex (Archbishop) on Nov 09, 2017 at 17:03 UTC

    The error probably has to do with the use of forward slashes in the filename, which appear to be interpreted as switches by rmdir.

    I strongly recommend you use remove_tree from File::Path, as several others have suggested. It has been a core module for over 20 years and should therefore not only meet your requirement of being "plain Perl", but unlike rmdir it is also platform-independent!

    Also, note that you probably don't want to use a "delete directory" function to delete individual files. See unlink for files.