Let's say I have this file:
C:\[foo]\bar
I then run these PowerShell commands:
$path = 'C:\[foo]'
get-childitem -literalpath $path
Everything works fine, get-childitem
shows me the file bar
, then returns immediately.
Now I add the -recurse
option:
$path = 'C:\[foo]'
get-childitem -literalpath $path -recurse
get-childitem
no longer displays the file bar
. In addition, the cmdlet runs a long time and displays various "permission denied" error messages for folders underneath C:\Windows
, apparently because it scans the entire C: drive.
The problem is tied to the fact that the folder [bar]
has brackets in the name. If I rename the folder to bar
, i.e. without brackets, the result with recursion works as expected.
My main question: How can I convince get-childitem
to recursively scan folders that have brackets (or other special characters) in the name?
A secondary question: Is this a known bug?
Environment: Windows 8.1, PowerShell 4.0.
EDIT: I verified that in PowerShell 2.0 (on a Windows 7 machine) get-childitem
returns the same result with or without -recurse
. It appears that the behaviour has changed either in version 3.0 or 4.0.