0

this deletes .unwanted directories from qbittorrent downloads. it works great but the esthetic side effect that I can't shake is that it echoes the file not found error if none are found.

for /f "delims=" %%u in ('dir .unwanted /a:d /b /s') do rmdir /s /q "%%u" 2>nul && if defined v%~n0 echo deleted "%%u"
Bricktop
  • 533
  • 3
  • 22
  • 2
    Redirect the error within the parentheses: `@For /F "Delims=" %%A In ('Dir /B/S/AD ".unwanted" 2^>Nul') Do @RD /S/Q "%%A" …` – Compo Sep 08 '18 at 14:04
  • 1
    @bricktop Read for example [this short answer](https://stackoverflow.com/a/45760973/3074564) if you want to know why `2^>nul` must be used instead of `2>nul` as usual in this case. – Mofi Sep 08 '18 at 17:41

1 Answers1

2

Better idea is to use /D /R than /F in the For loop for Directories. Check For /? documentation.

for /d /r %%u in (.unwanted) do rmdir /s /q "%%u" 2>nul & echo deleted %%u

This is assuming you are running this from the directory of execution. It will only echo when the directory is deleted without the ""