Page 1 of 1

Recursively Delete File Types From A Named Folder Only

Posted: 10 Jun 2020 14:20
by pmc181
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

Re: Recursively Delete File Types From A Named Folder Only

Posted: 11 Jun 2020 22:56
by Squashman
pmc181 wrote:
10 Jun 2020 14:20
I
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
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.

Re: Recursively Delete File Types From A Named Folder Only

Posted: 14 Jun 2020 05:07
by pieh-ejdsch
you can use a for /r loop in a recursive search

Code: Select all

( for /d /r %%a in (Target-Folder.?) do @ DEL /S /Q "%%a\*.psr" "%%a\*.zip" ) >Deleted-psr-zip.txt 2>&1
Phil