Windows PowerShell Home
Get-ChildItem -Recurse in PowerShell 3.0 falls into infinite loop
as Won't Fix
5/20/2013 4:30:01 AM
User(s) can reproduce this bug
If the folder contains another folder whose name is one or more spaces, then Get-ChildItem falls into infinite loop.
How often does this happen?
Have you seen this problem before in this product?
No, this is new to the most recent version
1. Create the new folder with name " " (one space character) in C:\Temp folder.
2. Run this:
Get-ChildItem "C:\Temp" -Recurse
List of folders expected.
to post a comment.
Please enter a comment.
on 8/7/2013 at 11:16 AM
I understand that this is an invalid file path, but wouldn't it be better to at least throw an error. Right now the default behavior seems to be to trim the blank space from any string prior to processing it. I know it is generally best practice to trim strings when taking input, but if there is a space in this string it is either because it is actually in the path or because I intentionally put it inside the quotes. If get-childitem would just throw an invalid path error instead of trimming and working itself in a loop it would be much nicer to use.
As it stands right now, I have to script my own recursion loop any time I'm running this command against a large data set just in case some joker decided to throw a space in there somewhere. An error, I can catch - an infinite loop I can't.
on 5/24/2013 at 2:29 PM
It doesn't seem that a file or folder name whose only characters are spaces is allowed. See http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx. "Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not." If you are able to somehow create a file or folder whose name contains only spaces, you will likely get unpredicable results in many scenarios other than Get-ChildItem -Recurse.
to post a workaround.
Please enter a workaround.
© 2013 Microsoft