0

I am new to the batch scripting. I would like to delete some folders and files using batch scripting. For example I have 10 folders under this directory "C:\test", in each folder there are files and folders available like "D:\test\check*". I have to navigate to "D:\test" and select a folder "D:\test\check", and navigate to the subfolders like "D:\test\check\folder1" and delete the files and folders there.

My script should come back to "D:\test", and select the appropriate folder, and navigate to destination folder to delete the text files and folders available. I am thinking if there is a possibility to write bat file which navigate back and forth to delete the files and folders. Currently I am deleting them by providing the destination path for file and folders, but I am not sure if that is the feasible solution or not. If use this method then I have to provide a explicit path to delete.

This is what I am using right now.

for /d %%p in ("D:\test\*") do (
    echo %%p
    del /s /q "D:\test\check\folder1\folder2\*.*"
    for /d %%p in ("D:\test\check\folder1\folder2\*.*") do rmdir "%%p" /s /q
)

Thanks in advance.

Kondal
  • 21
  • 1
  • 2
    Does this answer your question? [How to delete files/subfolders in a specific directory at the command prompt in Windows](https://stackoverflow.com/questions/1965787/how-to-delete-files-subfolders-in-a-specific-directory-at-the-command-prompt-in) – Daniel Brose May 14 '20 at 00:59
  • 1
    If that doesnt answer, then please improve your original question by adding a step by step or clear visual of how it doesnt, since i read it many times and not entirely sure how any of the dozen duplicate posts dont answer your question already (just search "delete files directory batch"). Create a local variable or hardcode the pathing in, then run the batch file... OR place a version of the batch file that deletes everything under it in the "check" directory level, then a single batch file to search for and calls/triggers/executes any of these "delete-contents.batch" files under "D:\test" – Daniel Brose May 14 '20 at 01:00
  • Take a look at the `/r` option with `for` loop and see if that helps (i.e. `for /r %%i in (.) do `). – jpf May 14 '20 at 01:22

0 Answers0