Batch file. Delete all files and folders in a directory

前端 未结 14 1356
无人共我
无人共我 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:46

    Use

    set dir="Your Folder Path Here"
    rmdir /s %dir%
    mkdir %dir%
    

    This version deletes without asking:

    set dir="Your Folder Here"
    rmdir /s /q %dir%
    mkdir %dir%
    

    Example:

    set dir="C:\foo1\foo\foo\foo3"
    rmdir /s /q %dir%
    mkdir %dir%
    

    This will clear C:\foo1\foo\foo\foo3.

    (I would like to mention Abdullah Sabouin's answer. There was a mix up about me copying him. I did not notice his post. I would like to thank you melpomene for pointing out errors!)

提交回复
热议问题