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

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

    I created the Path Length Checker tool for this purpose, which is a nice, free GUI app that you can use to see the path lengths of all files and directories in a given directory.

    I've also written and blogged about a simple PowerShell script for getting file and directory lengths. It will output the length and path to a file, and optionally write it to the console as well. It doesn't limit to displaying files that are only over a certain length (an easy modification to make), but displays them descending by length, so it's still super easy to see which paths are over your threshold. Here it is:

    $pathToScan = "C:\Some Folder"  # The path to scan and the the lengths for (sub-directories will be scanned as well).
    $outputFilePath = "C:\temp\PathLengths.txt" # This must be a file in a directory that exists and does not require admin rights to write to.
    $writeToConsoleAsWell = $true   # Writing to the console will be much slower.
    
    # Open a new file stream (nice and fast) and write all the paths and their lengths to it.
    $outputFileDirectory = Split-Path $outputFilePath -Parent
    if (!(Test-Path $outputFileDirectory)) { New-Item $outputFileDirectory -ItemType Directory }
    $stream = New-Object System.IO.StreamWriter($outputFilePath, $false)
    Get-ChildItem -Path $pathToScan -Recurse -Force | Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | Sort-Object -Property FullNameLength -Descending | ForEach-Object {
        $filePath = $_.FullName
        $length = $_.FullNameLength
        $string = "$length : $filePath"
    
        # Write to the Console.
        if ($writeToConsoleAsWell) { Write-Host $string }
    
        #Write to the file.
        $stream.WriteLine($string)
    }
    $stream.Close()
    

提交回复
热议问题