I have a question regarding batch scripts. Suppose I have multiple levels of subfolders in my My Documents folder.
C:\Users\ABC\Documents
One of the Subfolders is C:\Users\ABC\Documents\Folder1\Subfolder1.
I would like to write batch script that deletes all XML files in My Documents except the ones in Subfolder1.
Batch script to delete .txt files in all subfolders except one
Moderator: DosItHelp
-
- Posts: 3
- Joined: 05 May 2021 13:28
Re: Batch script to delete .txt files in all subfolders except one
I guess something like that should do the trick:
Steffen
Code: Select all
for /f "delims=" %%i in ('dir /ad /b /s "%userprofile%\Documents"^|find /i /v "\Documents\Folder1\Subfolder1"') do del /f /s /q "%%i\*.xml"
-
- Posts: 3
- Joined: 05 May 2021 13:28
Re: Batch script to delete .xml files in all subfolders except one
My goal is more complicated. Subfolder1 will possess its own set of subfolders which will vary with time. I would like to write batch script that will not delete XML files in all these subfolders.
Re: Batch script to delete .txt files in all subfolders except one
Remove option /S from the DEL command. My fault.
The script will exclude all paths which contain string "\Documents\Folder1\Subfolder1". This integrates the exclusion of any subfolder structure underneath "Subfolder1". If this is not the intended behavior, I still don't get it.
Steffen
The script will exclude all paths which contain string "\Documents\Folder1\Subfolder1". This integrates the exclusion of any subfolder structure underneath "Subfolder1". If this is not the intended behavior, I still don't get it.
Steffen
-
- Posts: 3
- Joined: 05 May 2021 13:28
Re: Batch script to delete .txt files in all subfolders except one
I was successfully able to apply this solution. Thank you for the help.