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?
1,642 7 7 gold badges 23 23 silver badges 51 51 bronze badges asked Sep 23, 2009 at 15:56 2,239 3 3 gold badges 16 16 silver badges 6 6 bronze badges How were these files created? Commented Mar 25, 2011 at 15:44Sorry 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) ?
Commented Sep 14, 2013 at 17:47@Mokubai- The duplicate question should be marked a duplicate of this one, as this question is older.
Commented Oct 12, 2015 at 8:25 @cybermonkey: And it has a better answer. Commented Mar 23, 2016 at 0:50 For further readers, the 7zip Method with CTRL + DELETE is the easiest method in my opinion. Commented Aug 14, 2016 at 15:46When you want to completely delete a directory and it contains long paths, robocopy does a VERY good job:
mkdir empty_dir robocopy empty_dir the_dir_to_delete /mir rmdir empty_dir rmdir the_dir_to_delete
This works because robocopy internally uses the Unicode-aware versions of Win32 functions, with the \\?\ prefix for file paths; those functions have a limit of 2¹⁶-1 (32,767) characters instead of 259.
You may need to go through this process more than once to get rid of all of the files.
742 1 1 gold badge 8 8 silver badges 16 16 bronze badges answered Aug 29, 2012 at 13:38 7,053 5 5 gold badges 24 24 silver badges 31 31 bronze badges Efficient when there is no shortname (8.3) stored in the filesystem. Commented May 11, 2013 at 10:43 This worked nicely with my stubborn Windows Store cache files that refused to be deleted. Thanks! Commented Mar 6, 2014 at 10:07 I had to add /purge to the robocopy line for this to work, but it did the trick after that Commented Jul 21, 2014 at 10:12Robocopy is what got me into this mess, but it never occurred to me to use Robocopy to get me out of it. Great answer! Thanks!
Commented Jul 25, 2014 at 21:07 @SarahofGaia, my bad, it's 2¹⁶ - 1 actually Commented Oct 12, 2015 at 8:14From 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
answered Sep 23, 2009 at 16:01
Will Eddins Will Eddins
3,612 2 2 gold badges 27 27 silver badges 28 28 bronze badges
I like that one, it's a nice bit of lateral thinking.
Commented Sep 23, 2009 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.
Commented Sep 23, 2009 at 16:03This 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 .. .
Commented Nov 21, 2011 at 2:48 @Bobson If you cannot dir use pushd instead. That worked for me. Commented Nov 19, 2013 at 10:59 This does not work with Windows 10, the displayed file name is the long one Commented Jun 9, 2017 at 15:49I 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.
answered Sep 23, 2009 at 17:40 5,480 1 1 gold badge 20 20 silver badges 23 23 bronze badgesThis was the only thing that worked for me. All the other tricks given here and in other forums such as this didn't work.
Commented Dec 26, 2010 at 1:23 Was the only suggestion that worked oddly enough. Commented Sep 24, 2014 at 19:54This worked for me, a shortcut that helped me was mv * 1 && cd 1 . This didn't work when multiple files were in the directory but at that point an rm -rf * usually did the trick.
Commented May 20, 2015 at 21:37 Can't do this in windows 10. rename throws "filename to long' error Commented May 29, 2016 at 20:09Not only did this fix the problem for me, it also explains how I ended up with the issue in the first place. I must have had a path that was near the limit, then I renamed a parent folder (added something like "backup Nov 2016 save" to the name) which pushed the files in subfolders over the limit. Good to know the cause as well as the solution, even though I know it can happen other ways too, I think this is a common way it happens to folks.
Commented Nov 8, 2016 at 20:46A 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.