# Deleting Files from a List

**URL:** <https://forums.powershell.org/t/deleting-files-from-a-list/293>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/deleting-files-from-a-list/293 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/deleting-files-from-a-list/293/1 "2011-12-31T18:30:00Z")

</div>

by Xasthur at 2012-10-28 18:19:33

> Fairly new to PowerShell, so bear with me here for a moment. I’ve got a folder with about 10,000 items in it. They’re all from a single archive so they’re all organized under the same naming scheme. The standard Windows 7 search doesn’t seem to have the ability to parse file names whilst recognizing brackets (), so I figured I’d use the PowerShell filter instead. Each file contains a letter in its name which signifies its country of origin, e.g. (E) = Europe. So, after changing to the directory, the following command is the one I used to generate my desired list and store it in a variable]$rsl = get-childitem -filter "_(E)_" -recurse[/powershell]Now I have all the names of the files I need to get rid of, but I’m not actually sure of how to delete them. My initial thought would be to do something along the lines of "$rsl | ForEach-Object" and using $\_ to hit every filename in the list, but I don’t know how to format it so that I could remove-item all of the files from the hard disk. Hopefully that’s clear enough, if not I can try to give some more detail.  
>   
> Thanks,  
> -X

by Klaas at 2012-10-29 01:45:05

> You can skip the variable assignment, and the foreach. The golden path in Powershell is to send objects to a pipeline:  
> `Get-ChildItem -filter "(E)" -recurse | Remove-Item -Whatif`  
>   
> You’ll get a list of files that would be deleted. If that pleases you, lose the -Whatif switch.

by Xasthur at 2012-10-29 13:09:30

> Yup, that worked. Guess I was just overthinking it a bit, but I also didn’t know about the -Whatif switch which is pretty useful. Thanks!  
>   
> -X

---

<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, 9:03pm UTC](https://forums.powershell.org/t/deleting-files-from-a-list/293/2 "2024-05-16T21:03:33Z")

</div>

Closed on May 16, 2024, 9:03pm UTC


