“Please help. I can’t delete a file due to the filename being too long.”
This one is a perplexing problem that can be solved in five seconds, and all it takes is a simple DOS command from the past. But first, let’s get introduced to one of the oldest errors that Windows throws up and the culprit behind them: Long Filenames (LFN).
What Are Long Filenames?
Long Filenames are inherited from Windows 95 and its MS-DOS architecture. The LFN system specified file and directory names of up to 255 characters. This was a change from the older 8.3 file naming convention of a maximum eight characters (after any directory path), followed optionally by a filename extension consisting of a period [.] and at most three more characters.
As Windows is backwards compatible, we will use this “interconversion” between the two file naming systems to solve our problem, because sometimes filenames will exceed the limits set for them.
Many Windows programs expect the maximum path length to be shorter than 255 characters. This limit excludes the file path under which it is located. But, when you copy a file from one location, it takes into account the entire file path.
Files with too long filenames can be a product of other operating systems. It can also be born as a cache file from a third-party software. Or, it can be a media file with a really long name. Sometimes, these files are also created if they exist in deeper directories like a network share.
You can manage such files with the software that created them. But if that fails, here’s a much easier solution.
Solving “Too Long” Filename Errors
It is a simple three-step process to delete a file with a long filename. The trick is to auto-generate a shorter filename and use that.
- Open a command prompt in the directory where the file is located.
- Use a DOS command to get the short filename in the 8.3 filename format.
- Now, use the DEL command in DOS for the file to delete the file.
Let’s see how it works with an example. Here we have a file with a long filename in a directory.
Open File Explorer and browse to the file in its directory. Press Shift and then right-click on an empty area. Choose Open command window here. A Command Prompt window will open with the path set to the directory you’re in.
Enter the DOS command for listing the files and folders in the current directory. The dir command is an internal command and is available on all Microsoft operating systems. The /X attribute displays the short names for non-8.3 filenames. You can also use DIR /X /P to pause and move from one screen to the next when there are too many files to examine.
The screenshot below shows you the text file we want to delete with the “modified” short filename.
So, you can see how we used DOS to “auto-generate” a shorter name for the file. Now, just use the simple DEL command on the short filename to remove the file. That’s it!
The lesson here is to not neglect DOS. There are a variety of useful DOS commands that can still save your day.
Have you come across the problem of too long filenames? What is the approach you used?
Image Credit: hanss via Shutterstock.com