Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: delete folder and its content with plain perl

by ytjPerl (Scribe)
on Nov 08, 2017 at 15:42 UTC ( [id://1202961]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1202961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-23 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found