ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    PS: Find File path Length

    Scheduled Pinned Locked Moved IT Discussion
    powershellserver 2012serverfilepathfile pathfile systemexceeds 260 limit
    1 Posts 1 Posters 731 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gjacobseG
      gjacobse
      last edited by

      Been searching for a way to find the File Path that exceeded the 260 character limit... Found this nice Powershell script to do just that.

      $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()
      
      1 Reply Last reply Reply Quote 5
      • 1 / 1
      • First post
        Last post