Path or filename too long

Avatar
17

Here is one that would fall nicely into Ask Paul on Friday, but I’m currently frustrated!!!

I’m currently moving user profiles from one partition to another (department changes) and Windows keeps complaining that it can’t read the files, because the path name or filename is too long!

Why the fragging* heck did Windows Server allow the files to be written in the first place, if the names are too fragging long?

So, now, I’m going through nearly 1,900 folders and 11,000 files looking for 350 files whose names were too long to be read, then manually renaming them to something shorter and copying them across!

The source and destination path depths are the same, so it isn’t that they are going to a deeper level that messes them up on the destination, they are “illegal” names where they currently are!

Windows can fire truck** right off!

* fragging: from Babylon 5, to allow characters to express themselves on a show to be aired at prime time.

** fire truck: from Jodi Taylor’s “Doing Time”, to allow the book to be aimed at younger readers, whilst also providing hilarity for older readers.

Comments (17)

17 responses to “Path or filename too long”

  1. Avatar

    ianw789

    I can't tell you how they were allowed to be created, but I hope you are using a script like this to find the offenders:


    $pathToScan = "C:UsersUsername" # The path to scan and the the lengths for (sub-directories will be scanned as well).

    $lengthThreshold = 205 # Set the threshold for what is to be listed


    Get-ChildItem -Path $pathToScan -Recurse -Force | Select-Object -Property FullName, @{Name="FullNameLength";Expression={($_.FullName.Length)}} | Sort-Object -Property FullNameLength -Descending | ForEach-Object {


       $length = $_.FullNameLength   


       if ($length -gt $lengthThreshold ) {

           $filePath = $_.FullName

           $string = "$length : $filePath"

           if ($string ) { Write-Host $string }

       }

    }

  2. Avatar

    Brett Barbier

    Use robocopy to do this... It supports long paths.

  3. Avatar

    winner

    You expect a 30 yo OS from Microsoft to actually check things?


    How naive of you!

  4. Avatar

    frank gleg

    The best suggestion that I can provide for this type of issues is LongPathTool. Best of luck.

  5. Avatar

    Patrick3D

    Used to see this a lot with IE Favorites being saved in nested folders with filenames equal to the title of the webpage that included a long subtitle or the first sentence of the page. Mainly scientists with a PHD in chemistry bookmarking white papers and research studies. Another contributing factor were PDFs they were generating by using a "print to PDF" option that generated PDF filenames using the same webpage title.

  6. Avatar

    hrlngrv

    Uh, there's a registry setting which allows for longer pathnames. I'd guess it's enabled by default on Windows file servers but not on client machines.

    HKLM\SYSTEM\CurrentControlSet\Control\FileSystem key, LongPathsEnabled value.

    Also seems to be a group policy setting: Computer Configuration > Administrative Templates > System > Filesystem, which has a policy named Enable Win32 long paths.

    Your employer doesn't permit you to perform web searches?

    This comes up on reddit every other week or so.

  7. Avatar

    coeus89

    Also to answer your question on how they can exist. One way is mapping a drive in file explorer. This essentially shortens the entire file path to a few characters. So then when you are actually trying to copy the full, unmapped file path, it can be more than the 260 or whatever characters that are allowed and windows will barf.

  8. Avatar

    coeus89

    This error drives me crazy. Supposedly they have fixed it but it remains off by default. This is because it can break some old applications that don't support long file names. Good luck. lmk how you make out.

    https://lifehacker.com/windows-10-allows-file-names-longer-than-260-characters-1785201032

  9. Avatar

    wright_is

    Thanks to Ian for the suggestion.

    The post is more a cry of why the heck Microsoft haven't sorted this out. It has only been a known bug for, what, 20-25 years...

    • Avatar

      hrlngrv

      In reply to wright_is:

      It hasn't been a bug. It's been a known limitation, a design choice.

      I understand how frustrating this is for you because It's happened to me a few times. However, some limits are practical necessities. There's also the chance that even if you restore these files, some Windows applications won't be able to use them directly due to pathnames being too long for the allocated blocks of memory meant to store them.

      How could such files be created in the first place? Ever used SUBST.EXE? For that matter, rename an existing directory with a longer name, and Windows doesn't recursively check pathnames for files under that directory. Not so much a question of what's allowed as what's checked.

  10. Avatar

    lvthunder

    I've found it's typically done by unzipping files with a long folder structure. Do people access these through a mapped drive? That could be it too. Windows allows P:somelongpathfile.txt where on the server it might be d:Datasharenamesomelongpathfile.txt. It is weird though.

  11. Avatar

    savoli

    Long path name is a familiar problem happens when the length is over 260 characters and you can just shorten the paths if you can, but if you have many you can just use the Long Path tool or Gs RichCopy 360, both are powerful with this case, google it

Leave a Reply