0
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.

1 Answer 1

2

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

12
  • 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\" Aug 5, 2017 at 11:17
  • Didn't I write: in a batch file change %A to %%A?
    – LotPings
    Aug 5, 2017 at 11:21
  • I don't want it to ask me for confirmation before deletion. What should I do? Aug 5, 2017 at 11:29
  • Once you are shure only desired folders are removed, reinsert the /Q
    – LotPings
    Aug 5, 2017 at 11:32
  • Do you mean this for /Q /D %A in (C:\Windows\SoftwareDistribution.bak*) Do @RMDir /S "%A"? Aug 5, 2017 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .