If you’ve ever encountered this problem, it might have been an easy solution for you. If you’ve seen this error more than twice, then you also know that it can be difficult to fix at times.
Hopefully you only come across a lot of simple fixes, but we’ll prepare you for less simple, guaranteed to work fixes.
Why is file name length an issue in Windows?
The long history of file names is a problem for operating systems such as Windows. There was a time when filenames could not exceed 8 characters plus a 3-character file extension. The best you could do is something like myresume.doc. This limitation is due to the design of the filesystem.
With the release of new versions of Windows, things have improved. We have moved from the old limited file system to the so-called new technology file system (NTFS). NTFS has brought us to the point where a file name could be 255 characters long and a file path could potentially be up to 32,767 characters. So how can we have filenames that are too long?
Windows has things known as system variables. These are variables that Windows depends on because Windows will always know what the variables mean and where they are, even as we move bits and bytes all over the place. The MAX_PATH system variable limits file names and file paths to 260 characters.
You might think that being a variable, we can change it. No, don’t. It’s like pulling the thread out of a sweater. As soon as one system variable changes, other system variables and their dependent components begin to unravel.
– /
How do you fix this then?
Easy Fix
If you’re lucky, you will receive an error message and find out exactly which filename is causing the problem. Or at least where to find the file. Maybe you have a filename that looks something like this:
C: User guymc Documents My Resumesresumewithanamesolong, which causes problems and becomes part of an article by some guys on the website howdoyoulikemenow.docx
pre>
It is quite obvious who is the culprit in this case. Find the file in Windows Explorer or File Explorer as it is called in Windows 10, click on it once, press F2 to rename it, and change that stupid filename to something more sensible. The problem has been resolved.
Least Easy Repairs
Solving this problem is not always easy. Sometimes, you cannot change the names of files or directories for some reason.
The following solutions will help you. It’s not hard to do.
Move, delete or copy files or directories using PowerShell
Sometimes you receive an error message when you try to move, delete, or copy directories with more than 260 characters in the file path.
Note that the words “directory” and “folder” are used interchangeably. From now on we will use the “catalog”. The following PowerShell cmdlets can also be used with files.
The file path may look something like this:
C: Users guymc Documents This Is Exactly The Precise Directory Path That I Need To Have To Keep My Files Sorted In A Manner That Makes Sense To Me So Lets Pretend This Is An Actual Filepath That You Might Also Have On Your Windows Computer And Not Over Think It Document.docx
This file path is 280 characters long. Therefore, we cannot copy the directory from there to another location using the usual copy-paste method. We get the “Destination path too long” error.
Let’s suppose that for some reason we cannot rename the directories where the file is attached. What are we doing?
Open PowerShell. If you haven’t used PowerShell yet, check out our article Using PowerShell for Home Users – A Beginner’s Guide. However, you can follow these steps without reading the article.
When PowerShell opens, you will be in the root directory of your custom directory. Let’s assume C: Users guymc is your user directory.
A directory named This is located inside the Documents directory. To go to the Documents directory, we use the DOS command cd Documents.
You will see that the prompt changes to C: Users guymc Documents. It’s good. We work closer to directories, which will make things easier.
Copy catalog using Copy-Item
We want to copy the This directory and its contents to ThatNewFolder. Let’s use the Copy-Item PowerShell cmdlet with the -Destination and -Recurse parameters.
-Destination tells PowerShell where we want to place the copy. -Recurse tells PowerShell to copy all items inside to the destination. When copying, the originals remain in place and all new ones are placed in the destination.
Copy element of this -Destination ThatNewFolder -Recurse
Moving a directory using Move-Item
Let’s say we want to move the This directory and all directories and files in it to ThatNewFolder. The original does not stay in place when moved.
We can use the Move-Item PowerShell cmdlet with the -Path and -Destination parameters. -Path defines the element we want to move, and -Destination tells PowerShell where we want it to.
The cmdlet will put This inside ThatNewFolder. It will also move everything inside that directory. Move-Item can be used to move files or directories, and it works regardless of the file path or file name length.
Move-Item -Path This -Destination ThatNewFolder
To verify that this worked, use the cd ThatNewFolder command to get into the ThatNewFolder. Then use the dir command to list directories in ThatNewFolder. You will see that this directory is there.
Remove directory with Remove-Item
If we want to remove this directory and everything in it, we use the Remove-Item cmdlet.
The Remove-Item cmdlet has some built-in security that makes it difficult to remove a directory with content inside it. In our example, we know we want to delete everything, so we will use the -Recurse options to delete everything inside, and -Force to do this without asking us if we are sure of every element inside.
Keep in mind! It will be extremely difficult to recover anything deleted in this way. You can try the methods described in the article “How to recover accidentally deleted files”, but don’t expect too much.
Remove-Item This -Recurse -Force
You can use the dir command again to see if it’s gone.
Make Windows 10 accept long file paths
If you know that you will consistently use long file paths and long file names, it will be easier for you to get Windows to work for you. It doesn’t make sense to use PowerShell for your day to day work.
There are two ways to do this. One is for Windows 10 Home users and the other is for Windows 10 Pro or Enterprise users. These methods may work for Windows 8.1 or earlier, but we cannot guarantee this.
Force Windows 10 Home to accept long file paths
To make Windows 10 Home accept long file paths, we need to open the Registry Editor. If you haven’t worked in Registry Editor before, be careful. Accidentally deleting or changing anything here can completely stop Windows from working.
Always back up the registry before making changes. Find out everything you need to know about it in our comprehensive guide to backing up and restoring your Windows Registry.
After opening Registry Editor and creating a backup, navigate to the HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Control FileSystem folder and find the LongPathsEnabled key.
Double click LongPathsEnabled. Make sure there is 1 in the Value field. Click OK to confirm the change.
Close the registry editor, and now you can work with insanely long file paths.
Make Windows 10 Pro or Enterprise accept long file paths
To enable Windows 10 Pro or Enterprise to use long file paths, we’re going to use the Group Policy Editor. It is a tool that allows us to set Windows operating policies at the computer and user level.
We have several articles on using Group Policy for things like disabling or enabling Internet Explorer settings or adding a message to the login screen.
Open the Group Policy Editor by going to the start menu and typing gpedit. The first result should be a change in Group Policy. Double click on it.
After opening the Group Policy Editor, navigate to Computer Configuration> Administrative Templates> System> File System. There you will see the Include Win32 Long Paths policy.
Double click on it to change the policy setting. Change it from Disabled to Enabled, then click OK to commit the change.
The policy may not take effect immediately. However, you can force a Group Policy update.
That’s it
There are other ways to get around long file names and file paths, but here we’ve covered the simplest and most efficient methods.
–