Hello,
I understand the 260 character limitation in certain Windows components and a 32k limitation in NTFS. Unfortunately, some of our users have outdone themselves in creating long paths, but I need to still work with these folders. I was using get-childitem, but was pointed in the direction of [System.IO.Directory] from .NET.
I have tried the following code:
$destinationpath = '\\?\UNC\server1\APPS\'
$Searchstring = "*"
$SearchOption = "AllDirectories"
#$folders=[System.IO.Directory]::GetDirectories($destinationpath,$SearchString,$SearchOption)
$folders=[System.IO.Directory]::GetDirectories($destinationpath)
Unfortunately, it fails with:
At C:\Users\heywoodg\Dropbox\Powershell\Scripts\temp.ps1:6 char:47
+ $folders=[System.IO.Directory]::GetDirectories <<<< ($destinationpath)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
The other code I tried was
$destinationpath = '\\server1\APPS\'
$Searchstring = "*"
$SearchOption = "AllDirectories"
$folders=[System.IO.Directory]::GetDirectories($destinationpath,$SearchString,$SearchOption)
#$folders=[System.IO.Directory]::GetDirectories($destinationpath)
This fails with:
Exception calling "GetDirectories" with "3" argument(s): "Could not find a part of the path '\\server1\apps\DEP-Administration\SECRETARIAT\Subsidiary Companies UK\Copmany UK Branch Global Developments Limited\OVERSEAS BRANCHES\Company UK Global Developments Limited - (Pakistan Branch)\Loan Agreements (not part of a project)'."
At C:\Users\heywoodg\Dropbox\Powershell\Scripts\temp.ps1:5 char:47
+ $folders=[System.IO.Directory]::GetDirectories <<<< ($destinationpath,$SearchString,$SearchOption)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
So, I have two questions.
1) What is the correct way to pass the UNC to [System.IO.Directory] (a normal UNC still seems affected by the long path issue)?
2) Is the code to search sub-folders correct?
Thanks