# Deleting file containing specific path

**URL:** <https://forums.powershell.org/t/deleting-file-containing-specific-path/14187>\
**Category:** PowerShell Help\
**Created:** [April 17, 2020, 12:42pm UTC](https://forums.powershell.org/t/deleting-file-containing-specific-path/14187 "2020-04-17T12:42:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonatantwn](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@jonatantwn](https://forums.powershell.org/u/jonatantwn)\
**Post date:** [April 17, 2020, 12:42pm UTC](https://forums.powershell.org/t/deleting-file-containing-specific-path/14187/1 "2020-04-17T12:42:12Z")

</div>

Hi Forum!

Does anyone know, if it is somehow possible to target files, that contains a path name accross multiple directories?

For an example:

Folder:/  
[Domain.com/content/system/](http://Domain.com/content/system/) **unwanted** /malicious.php  
[Domain.com/content/assets/objects/](http://Domain.com/content/assets/objects/) **unwanted** /anothermalicious.php

Is it possible to create a deletion process that scans the paths of all files, and then deletes them if the path contains **unwanted**?

Currently i have no example of code to execute this, i am struggling to find documentation regarding if this is even possible.

Can anyone point me in the right direction? 🙂

Best regards  
Jonatan

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [April 17, 2020, 12:48pm UTC](https://forums.powershell.org/t/deleting-file-containing-specific-path/14187/2 "2020-04-17T12:48:52Z")

</div>

you can always use Get-ChildItem with -Filter parameter. Below is an example.

```
Get-ChildItem -Path c:\RootFolder -Filter *unwanted* -Recurse -Directory
```

Save the output of the above expression in a variable and process further for deletion.

I suggest to read the help doc of Get-ChildItem and Remove-Item cmdlet.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/deleting-file-containing-specific-path/14187/3 "2024-05-16T20:29:53Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


