The Short Version:
- Open a command-prompt window (click the “Start” button then type “cmd”)
- Navigate to the folder that contains the offending folder (type “cd temp\foldername\whatever”)
- Rename the file or folder using the Win95/DOS long-file name; let's pretend it's called “invalidfilename ” (ren invali~1 goodname)
- Delete the folder (rd goodname)
The RIVETING Full Story:
One of my clients recently sent me a ZIP file with a bunch of songs he wanted to put on his website. When I extracted it, it created a folder that couldn't be read or deleted.
(See, the Windows file system doesn't allow question marks, slashes, quotes or spaces-at-the-end-of-folder-names whereas other operating systems do.)
In order to correct this issue, I called upon my brain to remember a few things from the Windows 95 days.
If you were a nerd back then, you might recall being super-excited that Windows finally began allowing long file names. What a marvel! What progress!
You might also recall that when you went into DOS, all your lovely file names — such as “omg this is a long file name” or “this is really amazing” — were butchered into “omgthi~1” and “thisis~1”
It made browsing and file-copying a serious hassle. 17 years later, I STILL have files on my drive with these pooched names…
Anyway, in order to delete a folder with an invalid name, you'll need to do a little old-school hacking.
- Open a command-prompt window (click the “Start” button then type “cmd”)
- Navigate to the folder that contains the offending folder (type “cd temp\foldername\whatever”)
- Rename the file or folder using the Win95/DOS long-file name; let's pretend it's called “invalidfilename ” (ren invali~1 goodname)
- Delete the folder (rd goodname)
HOORAY!
Vince
File name: 20201016_092537_~ : zsh.jpg
That colon before zsh is present in the file name.
`dir /x` doesn’t show an 8.3 file name.
`ren`, and every other command, shows “The system cannot find the file specified.
Linux is so much easier in this regard. “Invalid” characters in file names just need to be *escaped* with a backslash or appear in single-quoted strings.
RR
The easiest way .. I had a directory with a space in the end (eg: “9. name something “.
Windows couldn’t delete file .. then I figured.. how I got this name in the beginning?
It was using winrar or winzip in total commander.. then I figured.. let me create a new zip file and choose to delete after moving.. and tada!
I guess it’s because these zip/rar file are universal, so they handle naming in a different way..
steve
it’s 2020 and the bowels of dos still are needed to bail us out… ugh, thanks
Jody Hatton
haha 😄
StanJ
If your folder name has punctuation marks in it and can’t be found in DOS 8.3 mode, try replacing the punctuation mark with an underscore, like: _THOR_~1 for the folder named [Thor] something. Found that when the other suggestions didn’t work. 😉
Joe Buckley
Another option if you have WinRAR, Move the directory containing the invalid name to somewhere else, you will be left with just the invalid names in a convenient directory.
Then archive with the ‘delete after archiving’ option, then delete the archive.
Oliver McNabb
Thank you! This WinRAR trick worked perfectly. I had a folder with a bad file name that I could not delete. The dir /x did not work because, I guess, it is not turned on for that drive. I was not looking forward to turning it on and having to index the entire drive or whatever, or to installing some shady software.
Matheus S
This is ridiculous…
Worked for me too with 7-ZIP!
Got to rename the folder and delete.
len barrett
Filexile http://filexile.sourceforge.net/ is free and will delete long file names. https://www.7-zip.org/ will rename long file names and delete them if you wish it’s also free.
Alan Feldman
Thank you so much for this solution! That worked for me! Woohoo! Thanks!
Bart
great! what also worked for me:
del invali~1 (are you sure do delete the content, invali~1/*? y)
rd invali~1
@vbut: try to open cmd as administrator
David
I’m having same problem. I got a bunch of files from a friend who has a mac and one of the files has a name with the redirect character in it (e.g., “a -> b.abc”). It has no 8dot3 name so I can’t use that approach. Some folks elsewhere suggested using the 7-zip program but that chokes on the “>” as well. It’s not a huge deal to leave the file (it’s a 50MB file on a 1TB drive) but it would be nice to get rid of it if possible. I’m hesitant to try the chkdsk /x approach because there are 800GB of other files on this drive and I don’t want to take a chance that somewhere in there there’s a filename that chkdsk doesn’t like (and, for the record, chkdsk /f reports no errors so I’m not sure it even knows that this is an invalid file name). FWIW, this is on an old WinXP machine that I keep around for the handful of utilities I have that won’t run under newer versions of Windows. It IS an external drive, however, so if there are solutions for Win7 or Win8, I can move the drive over to one of my other machines.
Vbut
I got “Access is denied” in cmd. Please help!
debruces
Hi Xdude,
With your solution it helps to know the DOS (8.3) name of the offending folder with:
<<>>
And you save yourself the renaming step at the same time, in short:
——————————-
Here’s how:
1- Open a command-prompt window (click the “Start” button then type “cmd”)
2- Navigate to the folder that contains the offending folder (type “cd tempfoldernamewhatever”)
3- Type “dir /x” to locate the DOS 8.3 short file name of the folder you want to poof; let’s pretend it’s called “Invalid Folder Version 7.0.1880 (x64)” and dir /x shows its short name to be “invali~1.188”
4- Delete the folder (rd invali~1.188)
—————————
I had this exact problem and a google search brought me to your place, problem was neither chkdsk nor your initial solution helped cause I was unable to ascertain what 8.3 filename the damn folder got, remembered from some time ago to look for the “dir” switch to show 8.3 filenames with a “help dir” and the rest is History. 🙂
This way, no matter what, you’ll be able to delete it (Windows 7 64bits).
Take care
Nova
how do i navigate to the folder (2nd step)
XDude
Thanks for the feedback, I’ve updated my article accordingly. 🙂
You’ll need to type “cd tempfoldernamewhatever”
Experience from the old DOS days will definitely help, if you have it. 🙂
Andrew
This won’t work for me. I keep on getting “the system cannot find the path specified”. Is there some option I need to enable first in order for this to work?
Janak Nepal
If you need to delete files with invalid file names, all you need to do is:
1. Open the Command prompt.
2. Type this command: chkdsk drive: /f /x
e.g. c:chkdsk e: /f /x
It will delete the files with invalid file names…
XDude
I always get a little nervous whenever I bring out the auto-fixing, non-confirming chkdsk… sometimes it gets a little delete-happy. But yes, it would work. 🙂
Lloyd
Old school still works! Nice job
Sina Ahmadpour
You Are A Life Saver
You Are A Hero
I Love YOU!
justme
A really good solution. The probelm was a filename such as ‘afilename.*pg’
MSF
Great Help!!! Thank you!! Always wonder how Mr. Softy survives and thrives peddling such damaged goods…
Tom
LongPathTool is payware, unfortunately. Not paying for something I only need once every 2 years.
Ram Lalit
It can be deleted in linux OS,if you have access to.
jaywon51
Well, Long path tool can help on this situation. Thanks
Arash
Hehehehee 😀
Nice
Thanks 😉