in reply to Re: delete folder and its content with plain perl
in thread delete folder and its content with plain perl
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: delete folder and its content with plain perl
by roboticus (Chancellor) on Nov 08, 2017 at 15:32 UTC |