eberwolf
eberwolf

Reputation: 21

Dealing with blank folder names while using get-childitem in powershell

I built a script, that searches through all directories recursively with Get-ChildItem. The problem is, there exist directories with blank names (done with alt+255).

When the script encounters such a directory, it still lists the files in this directory, but does not search in its sub-directories.

Upvotes: 1

Views: 628

Answers (2)

Jason Snell
Jason Snell

Reputation: 1465

As @Bert Levrau mentioned above you can do a recursive search in CMD. Using Get-ChildItem in Powershell with a folder that has an ALT + 255 name will throw it into an infinite recursive loop. You can invoke a CMD process from Powershell though using the following example: $result = cmd /c $directoryPath /s

At that point, you can work through the result to find the information that you need.

Upvotes: 0

Bert Levrau
Bert Levrau

Reputation: 1055

I don't think it is possible in powershell. but you can skip to cmd and use

cmd -c dir $Location /s
that works!

Upvotes: 1

Related Questions