Windows – On Windows 7, how to find all the files whose filenames are too long

filenameswindows 7

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.

Best Answer

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.

Related Question