Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

get-childitem bug?

Closed Thread
 
Thread Tools Display Modes
Old 02-29-2008   #1 (permalink)
RJ
Guest


 

get-childitem bug?

I seems to me that the -include option doesn't work for a file extension. In
my output ( below) get-childitem finds the files in the current directory.
When I apply the -include foo* for a file NAME, it finds the files with the
pattern/wildcard. When I apply the -include *.txt no files are found ( see
last line below). Is it just me? Thanks for input or confirmation.

-------------------------------------------------------------------------------------
PS C:\Temp\foodir> get-childitem

Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/29/2008 9:59 AM 46 foo.txt
-a--- 2/29/2008 10:00 AM 21 foo2
-a--- 2/29/2008 9:57 AM 9 foo2.txt


PS C:\Temp\foodir> get-childitem .
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/29/2008 9:59 AM 46 foo.txt
-a--- 2/29/2008 10:00 AM 21 foo2
-a--- 2/29/2008 9:57 AM 9 foo2.txt

PS C:\Temp\foodir> get-childitem . -include foo*
Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/29/2008 9:59 AM 46 foo.txt
-a--- 2/29/2008 10:00 AM 21 foo2
-a--- 2/29/2008 9:57 AM 9 foo2.txt


*** Next line returns NO OUTPUT ****
PS C:\Temp\foodir> get-childitem . -include *.txt
PS C:\Temp\foodir>
Old 02-29-2008   #2 (permalink)
Shay Levi
Guest


 

Re: get-childitem bug?


Check te help for get-childitem include parameter:

-include <string[]>
Retrieves only the specified items. The value of this parameter qualifies
the Path parameter. Enter a path element or pattern, such
as "*.txt". Wildcards are permitted.

The Include parameter is effective only when the command includes the
Recurse parameter or the path leads to the contents of a dire
ctory, such as C:\Windows\*, where the wildcard character specifies the
contents of the C:\Windows directory.


That said, this should fix the problem:

get-childitem .\* -include *.txt


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I seems to me that the -include option doesn't work for a file
> extension. In my output ( below) get-childitem finds the files in the
> current directory. When I apply the -include foo* for a file NAME, it
> finds the files with the pattern/wildcard. When I apply the -include
> *.txt no files are found ( see last line below). Is it just me?
> Thanks for input or confirmation.
>
> ----------------------------------------------------------------------
> --------------- PS C:\Temp\foodir> get-childitem
>
> Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir
>
> Mode LastWriteTime Length Name ----
> ------------- ------ ---- -a--- 2/29/2008 9:59 AM
> 46 foo.txt -a--- 2/29/2008 10:00 AM 21 foo2 -a---
> 2/29/2008 9:57 AM 9 foo2.txt
>
> PS C:\Temp\foodir> get-childitem .
> Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir
> Mode LastWriteTime Length Name ----
> ------------- ------ ---- -a--- 2/29/2008 9:59 AM
> 46 foo.txt -a--- 2/29/2008 10:00 AM 21 foo2 -a---
> 2/29/2008 9:57 AM 9 foo2.txt
>
> PS C:\Temp\foodir> get-childitem . -include foo*
> Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir
> Mode LastWriteTime Length Name ----
> ------------- ------ ---- -a--- 2/29/2008 9:59 AM
> 46 foo.txt -a--- 2/29/2008 10:00 AM 21 foo2 -a---
> 2/29/2008 9:57 AM 9 foo2.txt
>
> *** Next line returns NO OUTPUT ****
> PS C:\Temp\foodir> get-childitem . -include *.txt
> PS C:\Temp\foodir>

Old 02-29-2008   #3 (permalink)
RJ
Guest


 

Re: get-childitem bug?



Shay, thanks. The qualified -path does solve the issue. I did read the
help originally, and I used Example 2 - (( C:\PS>get-childitem . -Include
*.txt -Recurse ))
which does not follow the Qualified -path requirement.
It seems inconsistent if one -include pattern works, and another -include
pattern doesn't work, when in both cases, the -path is not fully qualified.
Maybe better in 2.0...

I appreciate your help.


"Shay Levi" wrote:
Quote:

>
> Check te help for get-childitem include parameter:
>
> -include <string[]>
> Retrieves only the specified items. The value of this parameter qualifies
> the Path parameter. Enter a path element or pattern, such
> as "*.txt". Wildcards are permitted.
>
> The Include parameter is effective only when the command includes the
> Recurse parameter or the path leads to the contents of a dire
> ctory, such as C:\Windows\*, where the wildcard character specifies the
> contents of the C:\Windows directory.
>
>
> That said, this should fix the problem:
>
> get-childitem .\* -include *.txt
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > I seems to me that the -include option doesn't work for a file
> > extension. In my output ( below) get-childitem finds the files in the
> > current directory. When I apply the -include foo* for a file NAME, it
> > finds the files with the pattern/wildcard. When I apply the -include
> > *.txt no files are found ( see last line below). Is it just me?
> > Thanks for input or confirmation.
> >
> > ----------------------------------------------------------------------
> > --------------- PS C:\Temp\foodir> get-childitem
> >
> > Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir
> >
> > Mode LastWriteTime Length Name ----
> > ------------- ------ ---- -a--- 2/29/2008 9:59 AM
> > 46 foo.txt -a--- 2/29/2008 10:00 AM 21 foo2 -a---
> > 2/29/2008 9:57 AM 9 foo2.txt
> >
> > PS C:\Temp\foodir> get-childitem .
> > Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir
> > Mode LastWriteTime Length Name ----
> > ------------- ------ ---- -a--- 2/29/2008 9:59 AM
> > 46 foo.txt -a--- 2/29/2008 10:00 AM 21 foo2 -a---
> > 2/29/2008 9:57 AM 9 foo2.txt
> >
> > PS C:\Temp\foodir> get-childitem . -include foo*
> > Directory: Microsoft.PowerShell.Core\FileSystem::C:\Temp\foodir
> > Mode LastWriteTime Length Name ----
> > ------------- ------ ---- -a--- 2/29/2008 9:59 AM
> > 46 foo.txt -a--- 2/29/2008 10:00 AM 21 foo2 -a---
> > 2/29/2008 9:57 AM 9 foo2.txt
> >
> > *** Next line returns NO OUTPUT ****
> > PS C:\Temp\foodir> get-childitem . -include *.txt
> > PS C:\Temp\foodir>
>
>
>
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
get-childitem -exclude bug bep PowerShell 7 03-11-2008 07:47 PM
using Get-ChildItem foamy PowerShell 9 02-15-2008 04:32 AM
get-childitem Brandon Shell [MVP] PowerShell 4 12-03-2007 12:58 PM
Registry and Get-ChildItem fixitchris PowerShell 7 11-14-2006 06:02 PM
Problem with Get-ChildItem Gary PowerShell 3 09-26-2006 08:23 PM








Vistax64.com 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 2005-2008

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 47 48 49 50