Delete files in subfolder using batch script

后端 未结 5 1665
小鲜肉
小鲜肉 2020-12-30 14:06

I have to delete files from a sub folder with a same name. My file path is like as follows.

d:\\test\\test1\\archive\\*.txt
d:\\test\\try\\archive\\*.txt
d:\         


        
5条回答
  •  遥遥无期
    2020-12-30 14:36

    You can use the /s switch for del to delete in subfolders as well.

    Example

    del D:\test\*.* /s
    

    Would delete all files under test including all files in all subfolders.

    To remove folders use rd, same switch applies.

    rd D:\test\folder /s /q
    

    rd doesn't support wildcards * though so if you want to recursively delete all subfolders under the test directory you can use a for loop.

    for /r /d D:\test %a in (*) do rd %a /s /q
    

    If you are using the for option in a batch file remember to use 2 %'s instead of 1.

提交回复
热议问题