How do you delete a file whose name is too long? [

2019-06-21 07:31发布

问题:

I have never seen this issue before. Have you?

First of all, I have a file on an Windows 7 computer that I first tried to move from one folder to another and it threw an error that said that "The file name(s) would be tool long for the destination folder...".

So I first tried to copy it to the root, C, drive and it threw the same error.

So I tried to delete the file. And it threw the same error because clearly it was going to the Recycle bin.

So I tried alt-delete. Suprisingly, it threw the same error again.

The error says I can try to rename the file. I right click on the file and it does not provide that option.

So then I try the command line window that I open as an administrator. trying to delete the file says that the access is denied.

Yes, it is an AppData folder file, by the way. So it might be because of the system

回答1:

Sometimes I have had the same problem, and what has worked for me is to run robocopy: Try this: Onto the parent folder in which you want to delete, say parent>:

parent> mkdir new_empty_dir
parent> robocopy new_empty_dir dir_want_to_delete /s /mir
parent> rmdir new_empty_dir
parent> rmdir dir_want_to_delete

Hope this helps somebody else...



回答2:

I had the same issue when trying to delete spring tool suite installation which has some files with wierdly long names. I tried all other tricks suggested by other folks, but none worked. In the end, I went searching Windows Help, and found this "Windows limits a single path to 260 characters. This is why you might occasionally get an error when copying a file with a very long file name to a location that has a longer path than the file's original location. So, I shorterned each and every folder name in the file path to 3-char ones, guess what - I successfully deleted all those ugly long named files!

Hope this would help.



回答3:

I ran across this issue while I was using node. It created a HUGE amount of subfolders and when I tried to delete them I received the file name too long error. I used this very simple, free, open source Java program to remove them in about 5 seconds. I highly recommend it.

http://www.osmstudios.com/projects/path-too-long

The only prerequisite is to have Java installed. The source code is available on GitHub at https://github.com/DawsonG/PathTooLong .



回答4:

As this is a problem with Windows, and the same problem will arise even if you try to delete it through the CMD console; you can try to remove it using a virtual linux terminal application as cygwin or mobaxterm.

https://www.cygwin.com/

http://mobaxterm.mobatek.net/

In one of this applications, just go to the path where the file or directory you want to remove is and type:

rm foo (where foo is the name of the file)

or

rm -r foo (where foo is the name of the directory)

Hope this helps for anybody



回答5:

As a temporary work around, you could use Delimon Win32 Explorer, which uses a different library that gets around the 260-character issue (it supports up to 32K characters) and seems to work in Win7. Make sure you check the "Known Issues" section.

Source