Get-ChildItem error handling when using long file paths

后端 未结 2 1648
鱼传尺愫
鱼传尺愫 2020-12-12 03:17

I am trying to handle errors when scanning through folders. Let\'s say I have something like:

Get-ChildItem $somepath -Directory | ForEach-Object {
   if(err         


        
2条回答
  •  甜味超标
    2020-12-12 03:18

    If you can install a non-ancient PowerShell version (3.0 or newer), simply prepend the path with \\?\ to overcome the 260-character limit for full path:

    Get-ChildItem "\\?\$somepath" | ForEach {
        # ............
    }
    

提交回复
热议问题