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

后端 未结 8 1929
时光取名叫无心
时光取名叫无心 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:55

    I've made an alternative to the other good answers on here that uses PowerShell, but mine also saves the list to a file. Will share it here in case anyone else needs wants something like that.

    Warning: Code overwrites "longfilepath.txt" in the current working directory. I know it's unlikely you'd have one already, but just in case!

    Purposely wanted it in a single line:

    Out-File longfilepath.txt ; cmd /c "dir /b /s /a" | ForEach-Object { if ($_.length -gt 250) {$_ | Out-File -append longfilepath.txt}}
    

    Detailed instructions:

    1. Run PowerShell
    2. Traverse to the directory you want to check for filepath lengths (C: works)
    3. Copy and paste the code [Right click to paste in PowerShell, or Alt + Space > E > P]
    4. Wait until it's done and then view the file: cat longfilepath.txt | sort

    Explanation:

    Out-File longfilepath.txt ; – Create (or overwrite) a blank file titled 'longfilepath.txt'. Semi-colon to separate commands.

    cmd /c "dir /b /s /a" | – Run dir command on PowerShell, /a to show all files including hidden files. | to pipe.

    ForEach-Object { if ($_.length -gt 250) {$_ | Out-File -append longfilepath.txt}} – For each line (denoted as $_), if the length is greater than 250, append that line to the file.

提交回复
热议问题