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:\test\model\archive\*.txt
I tried deleting using del
command in batch script.
But there are more than 100 folders with in the folder "test". So it is very difficult to use del
for each and every path.
Except for the parent folder name of "archive" folder, everything remains the same for all the paths. So I guess there might be some easy way to delete the files using batch script.
Can anyone guide me whether there is any easy way to delete the files using batch script? Or i have to repeat del
for all 100 folders?
Best Answer
You can use the
/s
switch fordel
to delete in subfolders as well.Example
Would delete all files under test including all files in all subfolders.
To remove folders use
rd
, same switch applies.rd
doesn't support wildcards*
though so if you want to recursively delete all subfolders under thetest
directory you can use afor
loop.If you are using the
for
option in a batch file remember to use 2%
's instead of 1.