Batch file. Delete all files and folders in a directory

前端 未结 14 1350
无人共我
无人共我 2020-11-30 19:20

I want to have a batch file that will delete all the folders and files in my cache folder for my wireless toolkit.

Currently I have the following:

cd         


        
14条回答
  •  清歌不尽
    2020-11-30 19:30

    I just put this together from what morty346 posted:

    set folder="C:\test"
    IF EXIST "%folder%" (
        cd /d %folder%
        for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
    )
    

    It adds a quick check that the folder defined in the variable exists first, changes directory to the folder, and deletes the contents.

提交回复
热议问题