On Windows 7, how do I find all my files whose filenames are too long

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.


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


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.

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
::  ========================================================================  ::