Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
Tool for deleting directories with path/names too long for normal delete

My wife has several files and folders that somehow ended up having filenames that have caused them to be undeleteable (can't be deleted) by normal means or via the command line. I believe the filenames are too long due to the depth of the folder structures. Does anyone know of a good utility for cleaning up files like this?

share|improve this question

marked as duplicate by Nifle, Indrek, Diogo, 8088, Tom Wijsman Aug 31 '12 at 17:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
How were these files created? –  Nick Mar 25 '11 at 15:44
    
Sorry for my ignorance on this topic, but shouldn't Windows handle these files? Shouldn't what Will Eddins posted be done automatically by Windows (even from explorer) ? –  Stefanos Kalantzis Sep 14 '13 at 17:47
add comment

9 Answers

When you want to completely delete a directory and it has file with long names inside it, robocopy does a VERY good job:

mkdir empty_dir
robocopy empty_dir the_dir_to_delete /s /mir
rmdir empty_dir
rmdir the_dir_to_delete
share|improve this answer
    
Efficient when there is no shortname (8.3) stored in the filesystem. –  Antoine RODRIGUEZ May 11 '13 at 10:43
    
worked like a charm –  Keltari Aug 12 '13 at 17:41
    
I had a 8.3 filenames, but they didn't work. This did work. –  Ciantic Jan 18 at 20:44
    
This worked nicely with my stubborn Windows Store cache files that refused to be deleted. Thanks! –  sammyg Mar 6 at 10:07
    
Tried various other methods via cmd to no avail, but this worked for me! Thanks –  Simkill Apr 15 at 15:42
show 1 more comment

From a command prompt:

dir /X

This will list your files/folders in short name format. Then use the short name exactly as written to delete the file:

del LONGF~1.txt
share|improve this answer
    
I like that one, it's a nice bit of lateral thinking. –  Col Sep 23 '09 at 16:03
    
While I can't guarantee it will work in this case, I've used it several times to delete folders that have invalid characters at the end that make them impossible to delete by normal means. –  Will Eddins Sep 23 '09 at 16:03
    
I just used this technique to delete a file with an invalid filename - it was a file named "},". This tip solved it. Thanks Guard. –  Charles Roper Oct 3 '09 at 12:57
1  
This works for files and folders in the current directory, but if you somehow manage to find yourself inside a folder whose path is too long, it will not help. For example, I am currently in a console in a too-long path and cannot even dir or cd ... –  Bobson Nov 21 '11 at 2:48
    
@Bobson If you cannot dir use pushd instead. That worked for me. –  BadHorsie Nov 19 '13 at 10:59
add comment

I progressivley work my way into the path, renaming each successive parent folder to "1" and attempting to delete. You're effectively shortening the path each time and I've never had to work in by more than 4 or 5 directories until I'm finally able to delete the entire directory structure (which may or may not be what you want). You could do this from the last child folder as well and work your way up or down.

share|improve this answer
1  
This was the only thing that worked for me. All the other tricks given here and in other forums such as this didn't work. –  Andrew Arnott Dec 26 '10 at 1:23
    
Glad to help... –  joeqwerty Dec 26 '10 at 16:45
add comment

In some programs, including Command Prompt (cmd.exe), you can get around the file length limit by prefixing the full path with \\.\ like this:

\\.\C:\some directory\other directory\a file with long name
share|improve this answer
add comment

Rename the directory of cut/paste the file somewhere else, then delete it. Works here.

Or just from the command prompt, if you don't feel like going through the trouble.

share|improve this answer
add comment

A trick I have used to get round the "full path and filename" length limitation in order to move, copy or delete something is to shorten it by 'breaking in' halfway down (or more) using a mapped drive letter pointing to a folder way down the path.

so you have c:\some\long\path...\and\foo\bar\folders\oldfiles\myoldfile.txt.

Then map an arbitrary drive letter to somewhere along the path so that the first chunk of the path becomes only a few characters long. Pre-requisite - the folder must be in a shared folder (which it may already be if it is on a server, which is where I have needed to do this), and if it is not already then pick a folder somewhere in the path and share it. Depending on your environment and paranoia level, allow everyone modify access to the share as long as the NTFS permissions are reasonably restrictive. If you want, just allow modify rights only to your own account.

Now go to the shared folder or one inside it and share it, or use the command line as follows. Assume you shared folder "foo" as "fooshare", then you could do

net use x: \\mycomputername\fooshare\bar\folders /persistent:no

and the X: drive now points directly to the folder "folders" inside that share, so "x:\oldfiles\myoldfile.txt" is now pretty short.

(The "/persistent:no" means this won't survive the next reboot and confuse you later on. Don't forget to un-share your folder when done.)

Remember, you don't have to share the folder containing the file necessarily, if it is already inside a shared folder you can just map through the share and the nested folders to a target folder near to the file and that works fine.

I've had to use this technique doing a massive robocopy between two servers when we realised that users had mapped drives quite deep in the folder structure, so they had been able to use 255 characters from there, but that exceeded the total file path length when accessed from the local drive root.

share|improve this answer
add comment

The simplest way I've found is to boot from an ubuntu live CD.

As an alternative you can create a shared folder halfway down the path and then map a network drive to that and do the delete from the mapped folder (even on the same machine)

share|improve this answer
6  
It's funny how often an Ubuntu Live CD will help troubleshooting Windows problems ^^ –  Ivo Flipse Sep 23 '09 at 16:07
1  
I've noticed that myself, dodgy network try a live CD, filesystem issue try a live CD, corrupt partition table etc. etc. :-) –  Col Sep 23 '09 at 16:12
add comment

Probably not the best way and I am interested to see what others come up with -

I had this once and I tried a few things without any luck. Rather than looking for a good tool, I restarted with the Windows Disk in, went to the recovery console and just deleted it from there. Worked first time and really well!

Also, just did a Google for you and found this - DelinvFile Looks Good but cannot vouch for it.

Edit - Warning, just seen the above is only a trial - Maybe not as good as I first thought!

share|improve this answer
add comment

You could always try Unlocker as it has delete capabilities for 'awkward' files.

share|improve this answer
add comment

protected by Dennis Jan 26 '13 at 3:39

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.