I have a weekly cleanup routine I want to setup where I scan an entire directory of users folders and delete file types *.psr and *.zip but only in certain folders. Not every sub-folder.
Each user's folder in this directory has a sub-folder named the exact same name for all users. I only want to delete these files in the named sub-folder of each user. In the screen shot example below it would be the Target-Folder. The Target-Folder name exists for all users.
I came up with this Del statement to run and it works but deletes those file types from all sub-folders and not just the Target-Folder for each user.
DEL /S /Q *.psr *.zip > Deleted-psr-zip.txt 2>&1
This is a network file share server so I can't run powershell. I would like to use cmd's from a batch file.
Thanks,
Pmc181
Recursively Delete File Types From A Named Folder Only
Moderator: DosItHelp
Recursively Delete File Types From A Named Folder Only
- Attachments
-
- RemoveFiles.jpg (27.52 KiB) Viewed 4729 times
Re: Recursively Delete File Types From A Named Folder Only
That is fine if you want to use a batch file but it being a network file share does not rule out Powershell. In fact it probably makes the task easier.
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Recursively Delete File Types From A Named Folder Only
you can use a for /r loop in a recursive search
Phil
Code: Select all
( for /d /r %%a in (Target-Folder.?) do @ DEL /S /Q "%%a\*.psr" "%%a\*.zip" ) >Deleted-psr-zip.txt 2>&1