While working on my file servers, I have noticed one strange folder that broke my script. Folder has name consisting of only one character with ascii value 160 (non-breaking space, NBSP). Visually that name is the same as space character.
Briefly, I have Get-ChildItem
being executed on this folder and it is entering endless loop. Command is in reality executed against parent folder and it returns again problematic folder, so my script got into endless loop.
You can easily simulate this on your own environment. In C:\temp
folder create new folder whose name consists only of NBSP. You can type that with holding alt and pressing 0160 on numerical keyboard. After creating it, run
Get-ChildItem C:\Temp\ -Recurse
you will get endless list of folders without name, although I have only that one folder.
d----- 6/15/2017 2:20 PM
d----- 6/15/2017 2:20 PM
d----- 6/15/2017 2:20 PM
d----- 6/15/2017 2:20 PM
d----- 6/15/2017 2:20 PM
. . .
I tested this with PowerShell 4 and 5, on Server and Client OS and its the same behavior. Command Get-Item
is having also issue with this name, and both switches -Path
and -LiteralPath
are behaving in the same way. I tried also [System.IO.Directory]
class, but it was having the same issue.
Question: I have updated my script to report folders with this name as an error and skip it, but I am wondering is there some more smart way to do it? My goal would be to run Get-ChildItem
or equivalent against such folder.
Is this a known issue? Would be be worth reporting it somewhere as a bug, if confirmed by more people?