Avoid File not found in dir command

I am trying to delete from a folder all the folders that have a specific name like this

for /f "delims=" %%i in ('dir /b /ad /s CVS*') do rmdir /s /q %%i

The problem is that if the command 'dir /b /ad /s CVS*' returns the 'File Not Found' and the 'for' command will iterate over all the folders in my directory

Is there a way to make the command work in both cases: when folders exist and when they don't


  • [code]for /R /D %%i in (CVS*) do rmdir /s /q "%%i"[/code]
  • Thank you. It works
  • I spoke too soon

    You're code works if the command is executed in the directory where the folders are looked for.
    But since I am trying execute this command from any place it does not work.
  • [code]for /D /R "C: empAFolder" %%i in (CVS*) do rmdir /s /q "%%i"[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!