in reply to Re: delete folder and its content with plain perl
in thread delete folder and its content with plain perl

I am trying to use  my $result =  system ( 'rmdir /S /Q "$foldername"'); to delete the folder I created earlier in my script. But I got the error message that system cannot find the path. Do you know the problem here? I used both with quote and without. Thanks

Replies are listed 'Best First'.
Re^3: delete folder and its content with plain perl
by roboticus (Chancellor) on Nov 08, 2017 at 16:09 UTC

    ytiPerl:

    Inside single quotes, a variable is not expanded, so you're running "rmdir /S /Q $foldername".

    Try changing it to:

    my $result = system("rmdir /S /Q $foldername");

    Of course, if you have backslashes or spaces in the $foldername variable, then you'll get other problems. That's why you might want to consider using the list version of the system command, like:

    my $result = system('rmdir', '/S', '/Q', $foldername);

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      my $result = system('rmdir', '/S', '/Q', $foldername);?

      I used this, but as my $foldername path is d:\log_script\Archive I got error invalid switch - "log_script" , is that because "_" in my path?