Andrew Watt [MVP]
2006-07-07 20:43:45 UTC
I know this has been discussed before but I am still worried and
puzzled by the current semantics of get-childitem particularly when
used with the FileSystem provider.
One thing that worries me is the difference in semantics between
-Include and -Filter.
But why do we need both a -Filter and a -Include parameter at all? The
Help files are ... um ... unhelpful on that point as they are on the
exact semantics of either parameter. As is, so far as I can see, the
User Guide.
Examples of why I'm unhappy follow below.
First, I did what I expected would be a simple comparison to be sure
that -Include and -Filter gave me the same results doing a
"straightforward" search for *.txt. But it didn't. I got a different
count as in the following two commands.
PS C:\PowerShellScripts> (get-childitem * -Include *.txt).count
27
PS C:\PowerShellScripts> (get-childitem * -Filter *.txt).count
28
[I found that the discrepant result was a file named odd.txtcls when I
had attempted a pipe and, presumably added a cls in error. But why do
-Incude and -Filter treat this, admittedl unusual case differently?]
So far so puzzling but it becomes more puzzling. See the next four
commands.
PS C:\PowerShellScripts> (get-childitem -Include *.txt).count
PS C:\PowerShellScripts> (get-childitem -Filter *.txt).count
28
PS C:\PowerShellScripts> (get-childitem . -Include *.txt).count
PS C:\PowerShellScripts> (get-childitem . -Filter *.txt).count
28
Why does the -Filter count stay the same but the -Include count drops
to zero?
Another test was to see how -Filter behaved. In the following three
commands the same results were returned but in a different order when
* was used as the value for the (positional) Path parameter. Why
should the ordering of results be different?
PS C:\PowerShellScripts> get-childitem -Filter te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
d---- 07/07/2006 20:35 Test1
d---- 18/05/2006 09:42 Test2
d---- 18/05/2006 09:42 Test3
PS C:\PowerShellScripts> get-childitem . -Filter te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
d---- 07/07/2006 20:35 Test1
d---- 18/05/2006 09:42 Test2
d---- 18/05/2006 09:42 Test3
PS C:\PowerShellScripts> get-childitem * -Filter te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 07/07/2006 20:35 Test1
d---- 18/05/2006 09:42 Test2
d---- 18/05/2006 09:42 Test3
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
I then went on to compare the same three values for -Path (default, .
and *) using the -Include parameter and I got very different results
for the three commands.
Why do I only get two results for the following command? Why aren't
the folders test1, test2 and test3 displayed?
PS C:\PowerShellScripts> get-childitem * -Include te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
But, more confusing for me (at least) why do I get no results
displayed for the following two commands?
PS C:\PowerShellScripts> get-childitem -Include te*
PS C:\PowerShellScripts> get-childitem . -Include te*
PS C:\PowerShellScripts>
It seems to me that the semantics of the default path, . as a path and
* as a path are treated as the same when -Filter is used (except for
ordering of results in the second example) but the semantics of *
differs drastically from the default and . when -Include is used.
Now ... can somebody help to convince me that behaviour such as occurs
in the preceding examples makes good sense?
Thanks
Puzzled of Tunbridge Wells :)
alias
Andrew Watt MVP
puzzled by the current semantics of get-childitem particularly when
used with the FileSystem provider.
One thing that worries me is the difference in semantics between
-Include and -Filter.
But why do we need both a -Filter and a -Include parameter at all? The
Help files are ... um ... unhelpful on that point as they are on the
exact semantics of either parameter. As is, so far as I can see, the
User Guide.
Examples of why I'm unhappy follow below.
First, I did what I expected would be a simple comparison to be sure
that -Include and -Filter gave me the same results doing a
"straightforward" search for *.txt. But it didn't. I got a different
count as in the following two commands.
PS C:\PowerShellScripts> (get-childitem * -Include *.txt).count
27
PS C:\PowerShellScripts> (get-childitem * -Filter *.txt).count
28
[I found that the discrepant result was a file named odd.txtcls when I
had attempted a pipe and, presumably added a cls in error. But why do
-Incude and -Filter treat this, admittedl unusual case differently?]
So far so puzzling but it becomes more puzzling. See the next four
commands.
PS C:\PowerShellScripts> (get-childitem -Include *.txt).count
PS C:\PowerShellScripts> (get-childitem -Filter *.txt).count
28
PS C:\PowerShellScripts> (get-childitem . -Include *.txt).count
PS C:\PowerShellScripts> (get-childitem . -Filter *.txt).count
28
Why does the -Filter count stay the same but the -Include count drops
to zero?
Another test was to see how -Filter behaved. In the following three
commands the same results were returned but in a different order when
* was used as the value for the (positional) Path parameter. Why
should the ordering of results be different?
PS C:\PowerShellScripts> get-childitem -Filter te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
d---- 07/07/2006 20:35 Test1
d---- 18/05/2006 09:42 Test2
d---- 18/05/2006 09:42 Test3
PS C:\PowerShellScripts> get-childitem . -Filter te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
d---- 07/07/2006 20:35 Test1
d---- 18/05/2006 09:42 Test2
d---- 18/05/2006 09:42 Test3
PS C:\PowerShellScripts> get-childitem * -Filter te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 07/07/2006 20:35 Test1
d---- 18/05/2006 09:42 Test2
d---- 18/05/2006 09:42 Test3
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
I then went on to compare the same three values for -Path (default, .
and *) using the -Include parameter and I got very different results
for the three commands.
Why do I only get two results for the following command? Why aren't
the folders test1, test2 and test3 displayed?
PS C:\PowerShellScripts> get-childitem * -Include te*
Directory:
Microsoft.PowerShell.Core\FileSystem::C:\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 20/05/2006 09:34 158 TenLines.txt
-a--- 11/05/2006 21:53 137 TenNumbers.ps1
But, more confusing for me (at least) why do I get no results
displayed for the following two commands?
PS C:\PowerShellScripts> get-childitem -Include te*
PS C:\PowerShellScripts> get-childitem . -Include te*
PS C:\PowerShellScripts>
It seems to me that the semantics of the default path, . as a path and
* as a path are treated as the same when -Filter is used (except for
ordering of results in the second example) but the semantics of *
differs drastically from the default and . when -Include is used.
Now ... can somebody help to convince me that behaviour such as occurs
in the preceding examples makes good sense?
Thanks
Puzzled of Tunbridge Wells :)
alias
Andrew Watt MVP