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 - -filter multiple file extensions

Reply
 
Old 01-16-2007   #1 (permalink)
$hay


 
 

-filter multiple file extensions

is it possible to use the -filter | -exclude | -include
for multiple extensions, something like

get-childitem d:\test -filter *.vob,*.mp3,*.avi

i tried delimiting with ";" or "." or "," none worked


--
$hay
http://scriptolog.blogspot.com



My System SpecsSystem Spec
Old 01-16-2007   #2 (permalink)
Andrew Watt [MVP]


 
 

Re: -filter multiple file extensions

Hi Shay,

You can't do it using the -filter parameter since you are supplying an
array as value to a parameter which takes a string.

You can do it using -include but since you appear to have had problems
with that you are probably hitting one of the "features" of
get-childitem that, in my view, needs to be improved/corrected as soon
as possible.

Assume you are in the directory with the files. Then

PS C:\PowerShellScripts\MP3> get-childitem -include *.mp3,*.vob

returns nothing.

But if you add the *,

PS C:\PowerShellScripts\MP3> get-childitem * -include *.mp3,*.vob


Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts\MP3


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 16/01/2007 08:57 14 Empty1.mp3
-a--- 16/01/2007 08:57 14 Empty1.vob
-a--- 16/01/2007 08:57 14 Empty2.mp3
-a--- 16/01/2007 08:57 14 Empty2.vob
-a--- 16/01/2007 08:57 14 Empty3.mp3
-a--- 16/01/2007 08:57 14 Empty3.vob

it does what you wanted.

The same anomaly of semantics occurs if you use the full paths.

PS C:\PowerShellScripts\MP3> get-childitem C:\PowerShellScripts\MP3
-include *.mp3,*.vob
PS C:\PowerShellScripts\MP3> get-childitem C:\PowerShellScripts\MP3\*
-include *.mp3,*.vob


Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts\MP3


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 16/01/2007 08:57 14 Empty1.mp3
-a--- 16/01/2007 08:57 14 Empty1.vob
-a--- 16/01/2007 08:57 14 Empty2.mp3
-a--- 16/01/2007 08:57 14 Empty2.vob
-a--- 16/01/2007 08:57 14 Empty3.mp3
-a--- 16/01/2007 08:57 14 Empty3.vob


The presence or absence of the * is crucial to semantics.

The semantics of get-childitem have been flagged as a very important
bug for a long time. Unfortunately, it was resolved as "postponed" for
PowerShell 1.0. See
https://connect.microsoft.com/feedba...9321&SiteID=99
for an illustrative descriptionr of another of the problems of
semantics with get-childitem.

Since get-childitem can often be in an earlier pipeline step for
move-item or remove-item it seems to me that the semantics of
get-childitem need to be rock solid. At the moment that's not how I
would describe them, unfortunately.

I hope that helps.

Andrew Watt MVP
Author Professional Windows PowerShell (Wrox)


On Tue, 16 Jan 2007 09:39:59 +0200, "$hay" <no@addre.ss> wrote:

>is it possible to use the -filter | -exclude | -include
>for multiple extensions, something like
>
>get-childitem d:\test -filter *.vob,*.mp3,*.avi
>
>i tried delimiting with ";" or "." or "," none worked
>
>
>--
>$hay
>http://scriptolog.blogspot.com

My System SpecsSystem Spec
Old 01-16-2007   #3 (permalink)
$hay


 
 

Re: -filter multiple file extensions

great
just voted for it on connect

---
$hay
http://scriptolog.blogspot.com



"Andrew Watt [MVP]" <SVGDeveloper@aol.com> wrote in message
news:as5pq29o2eahft5rp6ail02l3pubt38q4f@4ax.com...
> Hi Shay,
>
> You can't do it using the -filter parameter since you are supplying an
> array as value to a parameter which takes a string.
>
> You can do it using -include but since you appear to have had problems
> with that you are probably hitting one of the "features" of
> get-childitem that, in my view, needs to be improved/corrected as soon
> as possible.
>
> Assume you are in the directory with the files. Then
>
> PS C:\PowerShellScripts\MP3> get-childitem -include *.mp3,*.vob
>
> returns nothing.
>
> But if you add the *,
>
> PS C:\PowerShellScripts\MP3> get-childitem * -include *.mp3,*.vob
>
>
> Directory:
> Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts\MP3
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> -a--- 16/01/2007 08:57 14 Empty1.mp3
> -a--- 16/01/2007 08:57 14 Empty1.vob
> -a--- 16/01/2007 08:57 14 Empty2.mp3
> -a--- 16/01/2007 08:57 14 Empty2.vob
> -a--- 16/01/2007 08:57 14 Empty3.mp3
> -a--- 16/01/2007 08:57 14 Empty3.vob
>
> it does what you wanted.
>
> The same anomaly of semantics occurs if you use the full paths.
>
> PS C:\PowerShellScripts\MP3> get-childitem C:\PowerShellScripts\MP3
> -include *.mp3,*.vob
> PS C:\PowerShellScripts\MP3> get-childitem C:\PowerShellScripts\MP3\*
> -include *.mp3,*.vob
>
>
> Directory:
> Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts\MP3
>
>
> Mode LastWriteTime Length Name
> ---- ------------- ------ ----
> -a--- 16/01/2007 08:57 14 Empty1.mp3
> -a--- 16/01/2007 08:57 14 Empty1.vob
> -a--- 16/01/2007 08:57 14 Empty2.mp3
> -a--- 16/01/2007 08:57 14 Empty2.vob
> -a--- 16/01/2007 08:57 14 Empty3.mp3
> -a--- 16/01/2007 08:57 14 Empty3.vob
>
>
> The presence or absence of the * is crucial to semantics.
>
> The semantics of get-childitem have been flagged as a very important
> bug for a long time. Unfortunately, it was resolved as "postponed" for
> PowerShell 1.0. See
> https://connect.microsoft.com/feedba...9321&SiteID=99
> for an illustrative descriptionr of another of the problems of
> semantics with get-childitem.
>
> Since get-childitem can often be in an earlier pipeline step for
> move-item or remove-item it seems to me that the semantics of
> get-childitem need to be rock solid. At the moment that's not how I
> would describe them, unfortunately.
>
> I hope that helps.
>
> Andrew Watt MVP
> Author Professional Windows PowerShell (Wrox)
>
>
> On Tue, 16 Jan 2007 09:39:59 +0200, "$hay" <no@addre.ss> wrote:
>
>>is it possible to use the -filter | -exclude | -include
>>for multiple extensions, something like
>>
>>get-childitem d:\test -filter *.vob,*.mp3,*.avi
>>
>>i tried delimiting with ";" or "." or "," none worked
>>
>>
>>--
>>$hay
>>http://scriptolog.blogspot.com



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Get-Childitem filter files with multiple extensions? PowerShell
Finding multiple file extensions Vista file management
Opening Multiple Files w/ Different Extensions Vista performance & maintenance
Search for Multiple Extensions Vista General
.doc file extensions Vista General


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