6

Dropbox tells me many of my files are not syncing because their name exceeds the max character length

https://www.dropbox.com/help/145/en

Max character length

Windows only allows file and folder names of 260 characters or less. Note that Windows counts the file path as part of the name, so a file like C:\Users\Panda\My Documents\Dropbox\Creative Nonfiction\My Autobiography\Favorite Things\Favorite Foods\Bamboo\Family Recipes\Fresh Leaves.doc would be 142 characters, not 16. If the entire file path and name exceed 260 characters, shorten the name or move the file or folder to a higher-level folder within your Dropbox.

How do I find all the files under a directory whose file and folder names are greater than 250 characters?

(Note: the "Check bad files" tool on that page doesn't find them either.)

Update: there are two suggestions so far, one using powershell that ironically, died when a filename grew too large, the other using cygwin's find and xargs, which may work, but is still running (several minutes later.)

I did solve my immediate problem.

In an emacs shell window, I ran a very simple find

$ find . -type f -print >> ../files.log

Then I opened that in emacs and typed m-x list-matching-lines ^ ESC 230 . RETURN

Which displays lines that match a regular expression, and the regular expression here is that the line contain at least 230 characters, where 230 was just a rough guess for lines that might be problematical. And that showed me two files that were too long.

For about 20,000 files that regular expression filter turned out to be almost instantaneous.

1
5

If you happen to have cygwin installed, I think this should work:

find /cygdrive/c/Users/username/Dropbox -type f -print0 | xargs -0 -I {} bash -c 'if [[ $(echo -n "{}" | wc -c) -gt "269" ]]; then echo "{}"; fi'

Sorry that I don't know of the native way of doing the same.

3
  • I have cygwin, so thanks. I think it might be nice to know if there is a standard windows way to do this, since apparently windows lets you make these files but doesn't let you easily discover them! Sep 20 '13 at 6:08
  • I tried that, and in fact, several minutes later it is still working (taskmgr confirms xargs is running quote a bit), and so far it has spit out $ find . -type f -print0 | xargs -0 -I {} bash -c 'if [[ $(echo -n "{}" | wc -c) -gt "255" ]]; then echo "{}"; fi' bash: -c: line 0: unexpected EOF while looking for matching )' bash: -c: line 1: unexpected token ÿ' in conditional command bash: -c: line 1: syntax error: unexpected end of file Sep 20 '13 at 6:28
  • 1
    Another update. I suspect the find from cygwin would have worked fine. It turned out the find in my PATH was coming from the native GIT installation. Sep 20 '13 at 7:17
3

Open up the Powershell console: Get-ChildItem -r * |? {$_.GetType().Name -match "File" } |? {$_.fullname.length -ge 260} |%{$_.fullname}

Credit to @rerun who posted this in Stack Overflow. https://stackoverflow.com/q/12697259/614863

1
  • 2
    Ironically, the above resulted in Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. At line:1 char:1 + Get-ChildItem -r * |? {$_.GetType().Name -match "File" } |? {$_.fullname.length ... + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (C:\Users\jerry\...\blogs\markdown:String) [Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand Sep 20 '13 at 6:17
1

Hmm -- find | xargs | bash - invocation of a single bash process (edit: oops - missed the xargs, sorry, pls ignore the rest of this paragraph :) to count just the length of one line, seems a bit 'process heavy'. There will be as many bash invocations as there are files, could be a lot...

find | awk will incur one process on each side (ie: only 2 processes)

Try this (for what should be a much faster result [edit: maybe not so with xargs]):

find . -type f | awk 'length > 259' > longfilename-list.txt

Assumptions: may be OS dependent, YMMV

  • find will default to printing the match, so no -print0 needed.
  • print $0 (the matching line) is default action in awk, so no {print} is required after the comparison.
3
  • -print0 is important if the file names could contain newlines. In addition for xargs it is also extremely important for file names containing other white spaces, quotes and backslashes. These all are by default separators and special characters for xargs! ------ Your code with awk is good except for file names containing newlines which is not probably allowed in Windows. ------ The code could be even shorter. . is default. And empty directory name lengths should be checked too: find | awk 'length > 259'
    – pabouk
    Dec 4 '13 at 8:02
  • Just to clarify, "." may be the default on some non-standard OS's. On FreeBSD 10.3: $ find -name "*.properties" -exec grep "^content.transformer" {} \; find: illegal option -- n $ find . -name "*.properties" -exec grep "^content.transformer" {} \; content.transformer.default.timeoutMs=blah From the man page: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] ... it is clear the path is not optional. Mar 22 '17 at 1:53
  • Thank you for your note. I did not know that. Also POSIX states that behaviour without a path parameter is "unspecified": pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html
    – pabouk
    Mar 22 '17 at 15:32
1

To supplement the previous answers given here, this might help the user to detect the presence of a (file or folder) path which exceeds the MAX_PATH maximum path length (260 characters).

Although there exist certain techniques for successfully overcoming the problem, Windows does not notify the user that the particular file access error is due to a MAX_PATH violation. Nor is there any method included in Windows to allow the user to test for that problem if an unusual access problem is encountered.

However, as the Windows file explorer (EXPLORER.EXE) is one of the Windows utils which can NOT cope with paths which exceed the limit, it can be a serious problem for an unwary user.

Here is a simple batch file, developed in Windows 7. Drag-and-drop a folder onto it, and it will test that folder and its sub-folders and files for MAX_PATH violations, will output results on the screen, and (but only if there are any violations of the MAX_PATH limit) will save a text file containing the full path to any objects which exceed the maximum 260 characters.

If no text file is written to the folder the batch file is run from, that means there is no MAX_PATH violation found.

@echo off && title Find Paths exceeding MAX_PATH in "%~n1"
mode 80,32750

::             *** Find Paths with Length exceeding MAX_PATH ***


    ::  Directory : Drag-and-drop
        SET directory=%~1


    ::  To access an object violating MAX_PATH, use extended-length path
    ::  syntax (only supported by some Windows functions): "\\?\" prefix.

::  ========================================================================  ::
    ECHO Searching Path lengths in "%~n1" --
::  ========================================================================  ::

::  ========================================================================  ::
    :: Command Extensions
    SetLocal EnableDelayedExpansion
::  ========================================================================  ::

::  ========================================================================  ::
    echo. & echo. & ECHO Directory - & echo.
::  ========================================================================  ::

::  ** Not Recursive : Directory **

    :: For Specified Directory
    IF "%directory:~260%"=="" (
        echo "%directory%" & echo[is shorter than 260 characters & echo.
    ) ELSE (
        echo "%directory%" & echo[is longer than 260 characters & echo.
        echo "%directory%" >> "Path Exceeds 260 chrs.txt"
    )

::  ========================================================================  ::
    echo. & echo. & ECHO Sub-Directories - & echo.
::  ========================================================================  ::

::  ** Recursive (FOR Loop) : Sub-Directories **

    :: For each Folder in Directory Tree
    FOR /D /R "%directory%" %%a IN (*.*) DO (
      set folder=%%a
      set folder=!folder:~260!
      if "!folder!"=="" (
          echo "%%a" & echo[is shorter than MAX_PATH & echo.
      ) ELSE (
          echo "%%a" & echo[is longer than 260 characters & echo.
          echo "%%a" >> "Path Exceeds 260 chrs.txt"
      )
    )

    ::  Notes -
    ::  No output if no Sub-Directories.

::  ========================================================================  ::
    echo. & echo. & ECHO Files - & echo.
::  ========================================================================  ::

::  ** Recursive (FOR Loop) : Files **

    :: For each File in Directory Tree
    FOR /R "%directory%" %%a IN (*.*) DO (
      set file=%%a
      set file=!file:~260!
      if "!file!"=="" (
          echo "%%a" & echo[is shorter than MAX_PATH & echo.
      ) ELSE (
          echo "%%a" & echo[is longer than 260 characters & echo.
          echo "%%a" >> "Path Exceeds 260 chrs.txt"
      )
    )

    ::  Notes -
    ::  No output if no Files.

::  ========================================================================  ::
    echo. & echo. & cmd /k
::  ========================================================================  ::
2
  • +1 for effort, but work is required to exclude conformant paths (use "not" and raise the "else" clauses".
    – mckenzm
    Sep 3 at 20:48
  • Well, nothing's perfect! But a Windows 7 user needs this solution, because a Windows system does not come with an emacs shell or cygwin or xargs or awk (required by the other suggestions). This solution only needs utilities that are installed with Windows, so no external software is necessary. The o/p asked for a solution for Windows, but none of the other solutions proposed are solutions for Windows!
    – Ed999
    Sep 11 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.