4

I'm helping my uncle transferring all his photography images from a Windows machines internal and external hard drives to his newly bought NAS and we stumbled across a little problem (happening to 'only' 3.000 files..), called 'File name/folder name too long to copy'. So.. I'm looking for an application that can find all files with a certain name length for me.

Windows Explorer can search by name, type, size, etc. but as far as I can tell it cannot search by name length. Therefor I'm looking for an application that can do so.

Note: This may be a prompt command providing that the outcome can simply be exported.


Bonus! Also applicable on the command prompt: changing file/folders name from the same application! Dashes, dots and spaces are in fact unnecessary and can result in shorter names, thus perhaps possible to transfer!

Sander Schaeffer
  • 217
  • 1
  • 4
  • 13
  • Shorten the folder names to those pictures, maybe you don't need to find out which file names are too long after doing that. Windows has a limit of 255 characters for a name, including path names. If the whole path to the file has more characters, you get the error message when copying. – daraos Mar 13 '16 at 22:21
  • Gotta find out if that applies also to Synology's OS, since that is the target folder. Thanks, clever! – Sander Schaeffer Mar 13 '16 at 22:22
  • i've done something like `c:\blah>dir /s/b>a.a` that gets a list of all filenames in a file `a.a`, and then open the file `a.a` in notepad and turn off word wrap and scroll right and scroll down and you see the longest paths. You could also open it in notepad++ and look for ways to sort by length of line. – barlop Mar 13 '16 at 22:27
  • Excuse me, I really got no clue what you are talking about, @barlop .. – Sander Schaeffer Mar 13 '16 at 22:28
  • @SanderSchaeffer well do you understand that if you have a list of all your filenames with their paths in a file, then you can see which are longest from the length of each line? – barlop Mar 13 '16 at 22:53
  • Yes, easily. But it was more the the items you put in 'code' :) – Sander Schaeffer Mar 13 '16 at 23:20
  • 4
    [How to copy files that have too long of a filepath in Windows?](http://superuser.com/q/216704/241386), [How to delete directories with path/names too long for normal delete](http://superuser.com/q/78434/241386) – phuclv Mar 14 '16 at 06:16
  • you don't need to search for them. Just find a solution to copy without length restriction. One is appending `\\?\` before the path – phuclv Mar 14 '16 at 06:19
  • Have you ever seen a command prompt? start..cmd see that thing, click it. That's where that dir command would be done. . – barlop Mar 14 '16 at 22:36
  • The funny thing is. Talking about command prompt, but giving a suggestion of a string without a proper function to start it. :) That's why I didn't understood your comment. You start with a directory, instead of a function. The outcome was "C:/ .. .. is not a function" :) But don't bother, since I solved it already. But thanks anyway! – Sander Schaeffer Mar 14 '16 at 22:39

2 Answers2

5

The Windows Explorer as well as .NET Framework applications have problems with paths that exceed 260 characters (see here: https://stackoverflow.com/questions/1880321/why-does-the-260-character-path-length-limit-exist-in-windows)

What you can do to circumvent this is simply shorten the path by means of mapping it to a drive letter with subst.exe like this:

subst.exe <DriveLetter>: <super long path without trailing backslash>

Example:

subst.exe A: C:\users\%username%\appdata\local\temp

This maps my super long path (C:\users\%username%\appdata\local\temp in this case) to the drive letter A: thus reducing the path length by more than 20 characters. This also works with UNC paths on your NAS.

The drive is visible in the Windows Explorer so you only have to open the commandline to map the drive. It'll automatically be unmapped when you log off/reboot the PC.

megamorf
  • 2,363
  • 15
  • 21
1

I'll shortcut your problem.

Your filespecs (the combination of the 8.3 filename and folder name) exceed the 255 character limit. This is likely due to deeply nested folders.

For the files that cannot be moved, move their folders to the root of the drive, and then perform the transfer operation. It should now work.

  • It would work if the new path is within the 255 char limit, which is likely.. but the destination path might have to be changed. And it's possible the filename is longer than it should be. – barlop Mar 13 '16 at 22:25
  • A quick thought: Most files that cannot be copied because of this error are located on internal NTFS drives. Each file has no issue staying there, which brings my thought: If they have no problem then the 255 character limit doesn't apply to them, so it shouldn't be the issue when moving them elsewhere. Or how should I see this? – Sander Schaeffer Mar 13 '16 at 22:27
  • @SanderSchaeffer it's possible to have a file existing there whose path exceeds the 255 limit, but then not be able to copy it. You ask a valid question of how did it get there, maybe it's possible to rename a file or create a file that exceeds the limit, but then have an issue copying it. There may be a way to copy it though just an issue with windows explorer copying and some others but. e.g. according to this, robocopy can do it http://stackoverflow.com/questions/29865863/how-to-move-folder-files-with-path-names-255-characters-in-windows-8-1 – barlop Mar 13 '16 at 22:29
  • It depends on how each application is written. Some applications, for example those written to use .NET, have their own limitations (260 chars). – RockPaperLz- Mask it or Casket Mar 13 '16 at 22:29