[SOLVED] Application or script to remove every folder containing specific "name".

6k38

Prominent
Jun 28, 2021
18
0
510
Is there an Application that can remove every folder containing a specific name string such as "coffee" in the C drive; including whats on "AppData, ProgramData" and other deeply rooted folders.
Example regid.1234-12.com.coffee where every folder containing the word "coffee" is deleted

Or what script does this? I tried this one proposed here https://stackoverflow.com/questions...e-folder-with-a-specific-name-with-powershell
---------------------------------------------------------------------------------------------------
Get-ChildItem -Filter coffee -Recurse -Force | Remove-Item -Recurse -Force
---------------------------------------------------------------------------------------------------

But i get this errors:
========================================================================================
Get-ChildItem : Access to the path
'C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache\Content.IE5' is denied.
At line:1 char:1
  • Get-ChildItem -Filter coffee -Recurse -Force | Remove-Item -Recurs ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\syst...che\Content.IE5:String) [Get-ChildItem], Unauthoriz
edAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Access to the path 'C:\Windows\system32\LogFiles\WMI\RtBackup' is denied.
At line:1 char:1
  • Get-ChildItem -Filter coffee -Recurse -Force | Remove-Item -Recurs ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\syst...es\WMI\RtBackup:String) [Get-ChildItem], Unauthoriz
edAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
========================================================================================
 
Check your syntax especially with the use of strings....

FYI:

https://stackoverflow.com/questions...or-strings-within-file-names-using-powershell

http://www.powershellcookbook.com/recipe/lvCW/find-files-that-match-a-pattern

https://docs.microsoft.com/en-us/po...ore/about/about_wildcards?view=powershell-7.1

One caution:

Focus on finding the files with a filename that contains the word coffee.

Inspect the results in case your cmdlet/script is also finding files that you do not want changed or removed.

Then pipe into Remove-Item.

Test on copies of the target folders as well. Back up everything in case the Remove-Item is too aggressive.
 
Last edited:
Out of curiosity, did your system get infected with malware, whereby it's generating a folder/file in every drive, folder and subfolder?
No. It's a persistent program i want to get rid of! I removed all registry entries of it. Now i want to remove every folder of it.
Manually i checked on "AppData and ProgramData", but folders could still be in other areas of the drive.
 
Last edited: