How do I find files with a path length greater than 260 characters in Windows?

后端 未结 8 1982
时光取名叫无心
时光取名叫无心 2020-12-04 06:11

I\'m using a xcopy in an XP windows script to recursively copy a directory. I keep getting an \'Insufficient Memory\' error, which I understand is because a file I\'m tryin

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 06:41

    From http://www.powershellmagazine.com/2012/07/24/jaap-brassers-favorite-powershell-tips-and-tricks/:

    Get-ChildItem –Force –Recurse –ErrorAction SilentlyContinue –ErrorVariable AccessDenied
    

    the first part just iterates through this and sub-folders; using -ErrorVariable AccessDenied means push the offending items into the powershell variable AccessDenied.

    You can then scan through the variable like so

    $AccessDenied |
    Where-Object { $_.Exception -match "must be less than 260 characters" } |
    ForEach-Object { $_.TargetObject }
    

    If you don't care about these files (may be applicable in some cases), simply drop the -ErrorVariable AccessDenied part.

提交回复
热议问题