Windows Filenames Exceeding 255 Characters

by Vince
in Blog
Hits: 4223

The maximum length filename (which includes the full path) cannot exceed 255 characters.  Just to be clear, that includes the directory name, spaces, punctuation or anything else that would appear in the address bar.  For example:

C:\Users\user\Desktop\filename.txt

The above is 34 characters in length.

While 255 characters might seem like a lot, and it does to me, there are some organizations where they push up against this limit regularly.  And don't ask me why but, in some instances, Windows will allow the user to exceed this length which causes all sorts of problems when you're restoring, copying or moving files.

I've come across this issue enough times that I've come up with a way to preempt the situation by providing the client with a list of the paths & filenames that need to be shortened in advance.

First, open a Command Prompt and move to the root folder of where you want to search.  Enter the following command:

dir /b /s > longfiles.csv

This will search all of the directories and subdirectories, list the files and paths and redirect the output to longfiles.csv

Now open that file with Excel and in Column A, you should have the listing of files.  If you move into Column B1 and enter:

=Len(A1)

The formula is setup with ' = '
The 'Len" command will return the number of characters in a text string.
'A1' is where Len is looking for characters to count.

Now you can copy B1, then click the top of Column B and paste which should copy the formula to all of the cells.  Depending on the number of files, this could take a file.  Once you have the character count, you can sort the files by longest file names by selecting Data, Sort.

In the field 'Sort by', select Column B and in the field 'Order', select Largest to Smallest then click OK.  Again, depending on the number of files, this could take a while.