Batch File for Searching a Directory and Deleting specific Folders

56 views Asked by At

I need to have a batch file or powershell script that will search a given directory when ran and delete any folders (and their files) that are inside that directory.

For Example: I am trying to delete folder called 'AppStore' that is located at C:\Users\Jeff\ AND also located at C:\Users\Jim AND c:\Users\Bob . So, I need to be able to delete the folder and corresponding files associated with the directorty in any folder under C:Users\ .

Thanks.

I have tried to write a batch file but I can only get it to delete the folders IF I know the exact path. And being as I would run this on multiple machines the path would change.

1

There are 1 answers

0
mklement0 On

Using PowerShell and its Remove-Item cmdlet (as noted, you'll need to run with elevation):

Remove-Item -Recurse -Force C:\Users\*\AppStore -WhatIf

Note: The -WhatIf common parameter in the command above previews the operation. Remove -WhatIf and re-execute once you're sure the operation will do what you want.