Destination path is too long. If a file with a long name is not deleted and an error appears that the file system does not support such long names? What to do if the path to the source is too long, how to delete such a file

It's no secret that windows explorer Like most other Windows applications, including PowerShell, they cannot work with deeply nested filesystem objects, path length to which exceeds 260 characters... Moreover, this limitation exists only at the application level, and the file itself NTFS system supports file paths up to 32767 characters.

This limitation is imposed by the library Win32 API, and which the maximum path length is 260 characters ( MAX_PATH = 260). In general, a path is formed from the following elements: + [path_from_256_characters] + [ ] , and the maximum length of one directory / file in NTFS is 255 characters in Unicode. When using unicode API functions, it is possible to use the path to 32767 characters. Thanks to this, many third party programs(the same popular file managers, for example FAR and Total commander) without any difficulty processes files / folders, the path length to which exceeds 260 characters.

Advice... You can bypass this Win32 API limitation and work with long file names by using the UNC path format, specifying the absolute path to the file using the extended-length path prefix. \\?\ ... For example, like this \\? \ C: \ SomeLongPath \ LongNameFile.txt

This limitation also does not apply when users have network access to files via the SMB protocol (due to this, directory structures with long paths are often on file servers with user data). Administrator serving this server cannot via standard explorer interface Windows Explorer manage (delete / move) files with long paths. When trying to create / copy a file to such a directory, an error appears:

Destination Path Too Long... The file name (s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorten path

Other programs / dialog boxes may indicate the presence of the restriction in their own way.

Agree, it's funny that 2014 is outside the window, and we are still talking about the 260 character limit on maximum length paths in Windows ... But it looks like no sooner drastic changes is not expected, and even in the very fresh Windows 10 Technical Preview, this limitation still exists.

In this article, we'll show you how you can work with files in Windows with paths longer than 260 characters. In this case, our task is to delete a directory containing files with long path lengths.

When trying to delete such a directory from the explorer, an error appears:

The file name (s) would be too long for the destination folder. You can shorten the file name and try again, or try a location that has a shorten path.

Powershell also does not know how to correctly handle directories and files with large paths exceeding 260 characters. When trying to delete a directory with such files (C: \ Install \ MS SQL 2012 Express Edition 64 bit \ verylongpath), an error appears:

Remove-Item. \ Verylongpath -Recurse

Remove-Item: The specified path, file name, or both are too long. The fully qualified file name must be less than 260
characters, and the directory name must be less than 248 characters.
At line: 1 char: 1
+ Remove-Item. \ Verylongpath -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: WriteError: (C: \ Install \ MS S ... it \ verylongpath: String), PathTooLongExcepti
on
+ FullyQualifiedErrorId: RemoveItemIOError, Microsoft.PowerShell.Commands.RemoveItemCommand

The simplest option (which, in fact, is offered in the window with an error) is to shorten the name of the parent folders by decreasing the total path length (but not always applicable).

Mklink / d c: \ install \ link “C: \ Install \ MS SQL 2012 Express Edition 64 bit \ verylongpath”

Another option, reminiscent of working with a symbolic link, is to map the problem folder to a virtual disk (in our example, X :), thereby also shortening the path length:

Subst X: “C: \ Install \ MS SQL 2012 Express Edition 64 bit \ verylongpath”

Now you can work with data on the X: drive, the paths to files in which will not exceed the limit. After finishing work, you can delete virtual disk:

Subst X: / d

But personally, most of all for the task of deleting data in such situations, I like the possibilities robocopy.exe which supports long paths.

With option / MIR, the robocopy utility can create a complete copy (mirror) of the source directory in the target. And, if the source folder is empty, all data in the target folder is cleared as well. Create an empty folder C: \ Install \ test and using the / MIR argument, copy the contents of the test folder to the target one (if the folder name contains spaces or Cyrillic characters, the path must be enclosed in quotes).

Robocopy / MIR C: \ Install \ test "C: \ Install \ MS SQL 2012 Express Edition 64 bit \ verylongpath"

After executing the command, the contents of the C: \ Install \ MS SQL 2012 Express Edition 64 bit \ verylongpath directory are cleared (replaced by the contents of the empty directory).

So, today we showed you some simple tricks that can be used when working with folders on file servers containing folders with path lengths greater than 260 characters.

Here is an example of a folder structure that I call a "big nesting doll":

As you can see, on the "D" (Data) drive there is an original video folder, there is a "Movies" folder in it, "Everything you need to watch movies" in it, and then in the same way a folder in a folder. At the same time, many folders have long names of names - more than 10-15 characters, which in total will give the volume of characters in all names more than 260. And if at the end of such a "matryoshka" there is a file, then it may turn out that you will not work with it you can ... Sometimes the system itself does not allow you to end up creating a folder or file that exceeds the allowable number of characters, but sometimes for some reason this happens.

At the beginning, for beginners, I will explain what the path to a file and folder is. The path is the so-called address on the computer where the file or folder is located. For example, a file called "My file.txt" is located on the local drive D: in the "Documents" folder. Then the path to this file will look like this:

D: \ Documents \ My file.txt

Or, for example, this is how the path from the example above, where I showed a complex folder structure, will look like.

As you can see, the number of characters in the path above is large and it is possible that at the end there will be a file or folder with a long name that you cannot delete.

When you try to delete a file with a long path name, you will get a window with an error like this:

I tried to artificially recreate the problem and this is what I got.

On disk "D" I created a folder with a short name "1" and put a file with a very long name into it. Here's an example:

Now I rename that folder "1" to some very long name, for example:

Interestingly, Windows freely allows you to rename a folder to such a long name, despite the fact that the number of characters in the name of this folder + file name already exceeds 260! Well, after such a renaming of a folder into a long name, I can no longer delete the file located in it and get the error shown.

Or here's another example ... I maintain the website of the Moscow Instrument-Making Technical School, where I previously worked full-time and sometimes to test some new "goodies" for the site I use a copy of the site on my computer. And then what if I install something bad and the site on the hosting dies? :) And so I check it on my computer and if everything is in order, then I already configure it on a real site located on a hosting. So, once I transferred the entire site from the hosting to test one thing and after I finished working, I decided to delete the folder with the site from my computer. After all, it weighs about 6 GB. The entire site was deleted, except for a number of folders. I started looking and saw that those folders that contained a file with a long name in the form of hieroglyphs were not deleted:

I tried again to delete this file with a long name and saw the same error that I mentioned above. I tried to rename it, it doesn't work either. Well, I had to think about how to solve the problem.

How to solve the problem of deleting a folder / file with a long path name!

I tried 2 ways how you can delete a folder / file with a long name in the path to them. Both of them are not technically difficult (especially the 1st), so I think a beginner can handle it if he does everything exactly as I show:

    Rename multiple folders in the file path to more short name... This is the simplest solution, which should already help many! Suppose you have a file in a folder with a very long name that you cannot delete, open, copy, and in general cannot work with.

    Then just try to rename the folder containing the file with a long name, for example, to "1". I will return to one of the examples above. Here is a folder with a long name:

    I rename the name of that folder to "1" through the standard Windows Explorer and this is how the path to the file now looks like:

    Now, you can safely work with the file, the system will open it, rename it and delete it.

    If you have a long tree of folders, i.e. like a nesting doll, in one folder there is another, in it again, then again, then start renaming from the very first folder from this nesting doll. Not from the last on the list, but from the first!

    It may be that there are a huge number of folders and it may not be possible to rename some of them due to the same error, or it will take you a lot of time. In this case, I suggest the second way.

    The way is that you can take a folder, for example, in the middle of a shared tree and connect it as a virtual disk. The virtual disk is what reminds us of a regular local disk, but which simply binds to a specific folder, for example, to quickly interact with it.

    Let's say you have a long path like this:

    D: \ Videos \ My Movies \ Everything you need to watch movies \ Programs for watching movies \ How to open MP4 movies \ List of MP4 sample movies \ List of programs to open MP4 \ What not to do when opening MP4 files

    Suppose that in the very last folder we have some problematic file that we cannot work with, since the path to it, as we can see, is quite a decent length :)

    We can take and connect one of the long-named folders in the middle of the path as a virtual disk. Let it be the "Programs for watching movies" folder.

    To connect a virtual disk, we need the so-called Windows command line, i.e. console.

    You can open it through Windows search... In the search and type "Command line":

    In the window command line we need to type the command:

    subst virtual_drive_letter "folder_path"

    You can put any drive letter, only so that it is no longer occupied by one of the local drives. For example, you have a local drive C and D, which means that you cannot call the virtual drive the same letter. You can call it, for example, the letter "X", because it is rarely used by anyone in Windows.

    As the path to the folder, you insert the path to the folder that you want to connect as virtual. As I already said, in my example we will make the virtual folder "Programs for watching movies", which means that the path must be specified like this:

    D: \ Videos \ My Movies \ Everything you need to watch movies \ Programs for watching movies \

    So, the final command in my case will look like this:

    subst X: "D: \ Videos \ My Movies \ Everything you need to watch movies \ Programs for watching movies \"

    To execute the entered command, press the "Enter" key on the keyboard. The virtual disk will be created.

    Now let's go to Windows Explorer, go to the "This computer" (or "Computer") section and see the created virtual disk there:

    You can distinguish it by letter. I assigned the letter "X" to the virtual disk. Now if you open this virtual disk, then we will immediately find ourselves in the "Programs for watching movies" folder. Those. we took and cut nafig half the path to the final folder.

    For comparison ...

    Previously, the path to the destination folder looked like this:

    D: \ Videos \ My Movies \ Everything you need to watch movies \ Programs for watching movies \ How to open MP4 movies \ List of MP4 sample movies \ List of programs to open MP4 \ What not to do when opening MP4 files

    After connecting the virtual disk to the "Programs for watching movies" folder, the path to the destination folder looks like this:

    X: \ How to open MP4 movies \ List of MP4 sample movies \ List of programs to open MP4 \ What not to do when opening MP4 files

    Do you feel the difference? The path is shortened in half, because the drive letter immediately directs us to the folder in the middle of the path :) And since the path is greatly shortened, you probably have now removed the character restriction in the names of files and folders and you can delete a file or folder with a long name!

    After you solve the problem with the file, you can delete the virtual disk again, so as not to annoy the eyes in the explorer.

    To do this, open the command prompt again. Windows string and enter the command:

    Subst virtual_disk_letter / d

    In my case, the drive letter is "X", so the command will look like this:

When I was thinking about solutions to the problem, how to delete a folder or file with a long name, I found another option on the Internet: delete the problem file using the Total Commander program. I tried it, it didn't work out, so I didn't recommend this method :)) And the method, even if it would have earned from someone, is honestly not cool, because you have to bet additional program to your computer to delete only one file or folder with a long name ...

I think that if a similar problem occurs, which I have encountered more than once, one of the above methods will definitely help you.

That's all! See you soon in the next articles;)

We got a long title, but it indicates the essence of the problem, which will be described here. I recently ran into a not-so-good situation. Sorting on the hard disk and cleaning it from unnecessary ones, I found that one of the files was not deleted, and an error appeared with the following content: “The file system does not support such long names source files... Try moving the file to a folder with a shorter path length, or specify a shorter file name and try again. "

Not only could I not delete the file, but I also failed to change the name to a shorter name. For many, this would seem like a dead end, because it turns out that the file cannot be deleted.

In fact, the problem is solved very simply and quickly, and now I will describe two methods for solving it, and which one to use is up to you.

What if the path to the source is too long, how to delete such a file?

If there is a file that cannot be deleted because of a long name, there are several ways to solve the problem. For example, a file is nested in several directories, say, five or even ten folders that have names of 10-20 characters each, then this may be the reason for not deleting the file. The fact is that Windows does not support any files with more than 260 characters in their names. If this limit is exceeded, then the error I showed above will appear. The number of folders that have their own names and the file name itself must add up to less than 260 characters. The system also has one feature - if this limit is exceeded, we can still rename folders. This means that you need to rename all folders to a short name, for example, a letter or a number.


This problem may appear not only because you gave such a long name. This happened for me when I decided to download the files of the sites from the server and do something. Since the files were no longer needed, I deleted the entire directory with the site files, but as it turned out, it contained a file with a very long name, plus the names of the folders, and this did not allow me to delete all this.

Method two will help if the first failed. The fact is that not all folders leading to a file with a long name can be renamed, and a file system error will still take off. Then you can create a virtual disk using any of the subfolders leading to the non-deleted file. Now I will show you how to do this.

We open the command line. To do this, press the combination Win + R and enter the command cmd... You can click right click mouse on the Start menu (Or the keyboard shortcut Win + X) and select the command line there.

Now you write a command like this, which will make a virtual disk for us:

You need to choose a drive letter that is not occupied by others. The system partition is usually indicated by the letters C, and the second partition, as D or E, then we choose any other.

The path to the folder must be specified from the disk. If this causes difficulty for you, then open the folder that will act as a virtual disk and copy the path to it in the explorer at the top.

My command looks like this:

When we go to My Computer, then there you should see a disk with the letter that we assigned to it from the command line. Thus, the path to the file will be reduced by almost half, which means that the total length of characters can be less than 260 characters. Now you can try to get rid of the non-removable.


In order to delete the virtual disk, you need to enter the command:

subst DriveLetter / d

Using Total Commander

On the Internet, I discovered a method that allows you to delete non-removable files using. Of course, the disadvantage here is that you have to install additional software on your computer, and not everyone will want to do this. In any case, I will leave this method here, suddenly someone wants to use it.

Download and install the program. Go to the tab "File" click on the section "Change Attributes"... A window appears where we remove the jackdaws from all attributes. If there is no check mark at the top opposite the item "Process directory contents"- we choose. Now we are trying to delete a file with a long name from the same program.


We use the archiver 7-Zip

For this case, we need a 7-Zip archiver. Right-click on the home directory and point the mouse to the partition "7-Zip" and select the item "Add to archive".

A window appears in which you only need to check one checkbox "Delete files after compression"... Then click OK.

An archive of all this stuff is created on the desktop, and folders with a long file are simply deleted. You can delete the archive itself without any problems.

We have considered such ways to fix the error of the not deleted file. Maybe you have more options on how you can do this?

Share this