Recursively delete all folders starting with

后端 未结 5 653
礼貌的吻别
礼貌的吻别 2021-02-05 20:24

I need to write a command in a .bat file that recursively deletes all the folders starting with a certain string. How may I achieve this ?

5条回答
  •  温柔的废话
    2021-02-05 21:20

    Unfinished, I think. If you meant "Recursively go down a directory hierarchy to delete all folders starting with a certain string", then the following might suffice:

    for /f "delims=" %%x in ('dir /b /ad abc*') do rd /s /q "%%x"
    

    This will recurse into the directory tree, finding all folders starting with "abc", iterate over that list and removing each folder.

    Maybe you need to wrap an if exist around the rd depending on the order in which directories are found and returned. In general, iterating over something and changing it at the same time is rarely a good idea but sometimes it works :-)

提交回复
热议问题