rmdir /s /q "C:\Windows\SoftwareDistribution.bak\" 

The above will delete a single folder: SoftwareDistribution.bak.
How can I delete all folders whose names are SoftwareDistribution.bak? For example, SoftwareDistribution.bak1, SoftwareDistribution.bak3, SoftwareDistribution.bak2, and so on.


Rmdir won't accept wildcards, so you have to enumerate the dirs first

for /D %A in (C:\Windows\SoftwareDistribution.bak*) Do @RMDir /S /Q "%A"

For security reasons I'd omit the /Q switch while testing.
In a batch file change %A to %%A

  • Do you mean the following? It did not work. No files were deleted. for /D %A in (C:\Windows\SoftwareDistribution.bak*) Do @RMDir /S "%A" rmdir /s /q "C:\Windows\SoftwareDistribution.bak\" – Matthew Wai Aug 5 '17 at 11:17
  • Didn't I write: in a batch file change %A to %%A? – LotPings Aug 5 '17 at 11:21
  • I don't want it to ask me for confirmation before deletion. What should I do? – Matthew Wai Aug 5 '17 at 11:29
  • Once you are shure only desired folders are removed, reinsert the /Q – LotPings Aug 5 '17 at 11:32
  • Do you mean this for /Q /D %A in (C:\Windows\SoftwareDistribution.bak*) Do @RMDir /S "%A"? – Matthew Wai Aug 5 '17 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.