Powershell Path Too Long

Jul 5, 2012 at 4:33 AM
Edited Jul 5, 2012 at 9:01 AM

I'm trying to use AlphaFS to overcome the file name and path too long issues when using PowerShell.

e.g. First I import-module alphafs.dll and then try to find all files with a specific character in the filename using the following command:

[Alphaleonis.Win32.Filesystem.Directory]::GetDirectories("C:\") | get-childitem | where {$_.name -match "A"}

However, I still get the same fime name\path too long errors.

Does anyone know of any solutions to this problem?

Thanks, Simon

Additional note:

This works:


but this dosen't:

[Alphaleonis.Win32.Filesystem.Directory]::GetDirectories(\\?\C:\) | get-childitem



Jul 6, 2012 at 2:28 PM

The output from the GetDirectories is just an array of strings, you should omit get-childitem  and where clause.

.\Bin\Debug> [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories("\\?\C:\") | select-string -pattern "A"


Also the next one is more easier way in the long run.

\Bin\Debug> [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories([Alphaleonis.Win32.Filesystem.Path]::GetLongPath("C:\")) | select-string -pattern "Prog"

\\?\C:\Program Files


The following one uses recursion. Be careful as the resulted output array may be too big for PowerShell and it may crash.

\Bin\Debug> [Alphaleonis.Win32.Filesystem.Directory]::GetDirectories([Alphaleonis.Win32.Filesystem.Path]::GetLongPath("C:\TargetDir"), "*A*", 1)

Jul 9, 2012 at 2:36 AM

Hi normalex,

Thanks for the info. I gave up with PowerShell and built a C# project with AlphaFS instead, which seems to be working well.

I'm still curious and would like to know if it's possible to do what I'm after using PowerShell. I'm trying to recurse a folder structure looking for items with a specific hex character and replacing that character with a zero length string. Here's my PowerShell command:

 get-childitem -recurse | where {$_.name -match "\uF028"} | rename-item -newname { $_.name -replace '\uF028','' }

Many thanks,





Nov 10, 2012 at 9:24 AM

Long Path Tool helped me in this situation.