Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Get-Childitem filter files with multiple extensions?

Reply
 
Old 07-16-2008   #1 (permalink)
akcorr


 
 

Get-Childitem filter files with multiple extensions?

Is there any way to run a get-childitem and filter for multiple objects?
Example
Get-Childitem -path C:\ -filter *.log,*.txt

I guess I could enter the extensions in an array and run though a loop
appending the results? Just wondering if there was an easier way


My System SpecsSystem Spec
Old 07-16-2008   #2 (permalink)
Kiron


 
 

Re: Get-Childitem filter files with multiple extensions?

Use the -Include parameter to qualify the -Path which should have a '\*'

ls c:\* -i *.log, *.txt

--
Kiron
My System SpecsSystem Spec
Old 07-16-2008   #3 (permalink)
Brandon Shell [MVP]


 
 

Re: Get-Childitem filter files with multiple extensions?

Try this. Include takes an array and filter only uses one string.

dir -path c:\data -Include @("*.txt","*.log") -rec

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

a> Is there any way to run a get-childitem and filter for multiple
a> objects?
a> Example
a> Get-Childitem -path C:\ -filter *.log,*.txt
a> I guess I could enter the extensions in an array and run though a
a> loop appending the results? Just wondering if there was an easier
a> way
a>


My System SpecsSystem Spec
Old 07-16-2008   #4 (permalink)
akcorr


 
 

Re: Get-Childitem filter files with multiple extensions?

Nice. Thanks. I was on right track...I did -include "*.txt,*.log" instead
but it obviously failed. Thanks for your help!

"Brandon Shell [MVP]" wrote:
Quote:

> Try this. Include takes an array and filter only uses one string.
>
> dir -path c:\data -Include @("*.txt","*.log") -rec
>
> Brandon Shell
> ---------------
> Blog: http://www.bsonposh.com/
> PSH Scripts Project: www.codeplex.com/psobject
>
> a> Is there any way to run a get-childitem and filter for multiple
> a> objects?
> a> Example
> a> Get-Childitem -path C:\ -filter *.log,*.txt
> a> I guess I could enter the extensions in an array and run though a
> a> loop appending the results? Just wondering if there was an easier
> a> way
> a>
>
>
>
My System SpecsSystem Spec
Old 07-16-2008   #5 (permalink)
Shay Levy [MVP]


 
 

Re: Get-Childitem filter files with multiple extensions?

Hi akcorr,

You can with -include, just make sure to add the '*' wildcard to the end
of the path (it leads to the contents of the directory).
You can omit the wildcard if you specify -recurse:

PS > Get-Childitem -path C:\* -include *.log,*.txt


---
Shay Levy
Windows PowerShell MVP
blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic



a> Is there any way to run a get-childitem and filter for multiple
a> objects?
a> Example
a> Get-Childitem -path C:\ -filter *.log,*.txt
a> I guess I could enter the extensions in an array and run though a
a> loop appending the results? Just wondering if there was an easier
a> way
a>


My System SpecsSystem Spec
Old 07-16-2008   #6 (permalink)
Kiron


 
 

Re: Get-Childitem filter files with multiple extensions?

Thanks Keith.

--
Kiron

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
should this work: Get-ChildItem -Path * -Filter *.ps1 -Recurse PowerShell
Finding multiple file extensions Vista file management
Opening Multiple Files w/ Different Extensions Vista performance & maintenance
Search for Multiple Extensions Vista General
-filter multiple file extensions PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46