in reply to What is wrong with this code?

I get that too, because the path "c:\ProgramData\Test1\Test Folder" does not exist on my system. Perhaps you should check that something exists before being surprised when you can't get a directory list? See -X.