I had thought roboticus was probably right about requiring cmd /c. So I thought salva's answer wasn't enough; but it turns out to be right (sorry for doubting you, ++salva): you don't need the cmd /c, and all you need is to provide the proper switches to rmdir:

C:\Temp>mkdir delme.dir\subdir C:\Temp>dir /S delme.dir Volume in drive C is System Volume Serial Number is ... Directory of C:\Temp\delme.dir 11/07/2017 06:44 AM <DIR> . 11/07/2017 06:44 AM <DIR> .. 11/07/2017 06:44 AM <DIR> subdir 0 File(s) 0 bytes Directory of C:\Temp\delme.dir\subdir 11/07/2017 06:44 AM <DIR> . 11/07/2017 06:44 AM <DIR> .. 0 File(s) 0 bytes Total Files Listed: 0 File(s) 0 bytes 5 Dir(s) 45,598,023,680 bytes free C:\Temp>perl -le "print system(qq(rmdir delme.dir)) && $! || 'deleted' +" The directory is not empty. No such file or directory C:\Temp>perl -le "print system(qq(rmdir /S delme.dir)) && $! || 'delet +ed'" delme.dir, Are you sure (Y/N)? n No such file or directory C:\Temp>perl -le "print system(qq(rmdir /S /Q delme.dir)) && $! || 'de +leted'" deleted C:\Temp>dir /S delme.dir Volume in drive C is System Volume Serial Number is ... File Not Found

But ytjPerl should also study/learn from the other responses, because TIMTOWTDI. And if you are sticking with system, use the multi-argument version that roboticus showed, and beware of quoting and backslashes. My oneliners above were for ease of typing, and to prove salva's point, not for robust and good coding style.


In reply to Re^2: delete folder and its content with plain perl by pryrt
in thread delete folder and its content with plain perl by ytjPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.