How to force Windows to rename a file with a special character?
Solution 1
Grab a linux live-cd and use that.
Solution 2
Have you tried using the short filenames version of its name? Eg
ren whereh~1.ogg where.ogg
If it's the only file in the current folder that starts with the first few letters, then use the first 6 letters of the name (ignoring spaces) followed by a tilde (~) then a 1.
Solution 3
- In Windows 7: Run cmd.exe in Administator Mode.
- cd into the Directory with the filenames.
- run: chkdsk /V /f [My bad files were on another drive other than the OS drive, so it was able to dismount it. If it is the OS drive, it may have to do this stage at startup.]
- Wait (May have to reboot).
As you will see the result was that chkdsk actually deleted the files for me. So, if you want to keep the files, I don't know what to do, but this will get rid of the files for sure.
Results/Cmd Log:
E:\islag\Music\llb>dir
Volume in drive E is FreeAgent Drive
Volume Serial Number is 5038-892A
Directory of E:\islag\Music\llb
02/02/2011 12:18 PM <DIR> .
02/02/2011 12:18 PM <DIR> ..
04/04/2010 02:19 PM 4,014,099 01 Los Lonely Boys - Se?orita - www.file2
4ever.com.mp3
04/04/2010 02:18 PM 3,125,942 12 Los Lonely Boys - La Contestaci?n - ww
w.file24ever.com.mp3
2 File(s) 7,140,041 bytes
2 Dir(s) 87,743,991,808 bytes free
E:\islag\Music\llb>chkdsk /V
The type of the file system is NTFS.
Volume label is FreeAgent Drive.
WARNING! F parameter not specified.
Running CHKDSK in read-only mode.
CHKDSK is verifying files (stage 1 of 3)...
231424 file records processed.
File verification completed.
34 large file records processed.
0 bad file records processed.
0 EA records processed.
0 reparse records processed.
CHKDSK is verifying indexes (stage 2 of 3)...
18 percent complete. (29338 of 245164 index entries processed)
An invalid filename 01 Los Lonely Boys - Se?orita - www.file24ever.com.mp3 (3196
6) was found in directory 31962.
All filenames for File 31966 are invalid.
Minor file name errors were detected in file 31966.
An invalid filename 12 Los Lonely Boys - La Contestaci?n - www.file24ever.com.mp
3 (31973) was found in directory 31962.
All filenames for File 31973 are invalid.
Minor file name errors were detected in file 31973.
73 percent complete. (233817 of 245164 index entries processed)
Index entry 01 Los Lonely Boys - Se?orita - www.file24ever.com.mp3 in index $I30
of file 31962 is incorrect.
Index entry 12 Los Lonely Boys - La Contestaci?n - www.file24ever.com.mp3 in ind
ex $I30 of file 31962 is incorrect.
245164 index entries processed.
Index verification completed.
Errors found. CHKDSK cannot continue in read-only mode.
E:\islag\Music\llb>dir
Volume in drive E is FreeAgent Drive
Volume Serial Number is 5038-892A
Directory of E:\islag\Music\llb
02/02/2011 12:18 PM <DIR> .
02/02/2011 12:18 PM <DIR> ..
04/04/2010 02:19 PM 4,014,099 01 Los Lonely Boys - Se?orita - www.file2
4ever.com.mp3
04/04/2010 02:18 PM 3,125,942 12 Los Lonely Boys - La Contestaci?n - ww
w.file24ever.com.mp3
2 File(s) 7,140,041 bytes
2 Dir(s) 87,743,991,808 bytes free
E:\islag\Music\llb>chkdsk /V /f
The type of the file system is NTFS.
Cannot lock current drive.
Chkdsk cannot run because the volume is in use by another
process. Chkdsk may run if this volume is dismounted first.
ALL OPENED HANDLES TO THIS VOLUME WOULD THEN BE INVALID.
Would you like to force a dismount on this volume? (Y/N) y
Volume dismounted. All opened handles to this volume are now invalid.
Volume label is FreeAgent Drive.
CHKDSK is verifying files (stage 1 of 3)...
231424 file records processed.
File verification completed.
32 large file records processed.
0 bad file records processed.
0 EA records processed.
0 reparse records processed.
CHKDSK is verifying indexes (stage 2 of 3)...
18 percent complete. (29339 of 245164 index entries processed)
Deleted invalid filename 01 Los Lonely Boys - Se?orita - www.file24ever.com.mp3
(31966) in directory 31962.
File 31966 has been orphaned since all its filenames were invalid
Windows will recover the file in the orphan recovery phase.
Correcting minor file name errors in file 31966.
Deleted invalid filename 12 Los Lonely Boys - La Contestaci?n - www.file24ever.c
om.mp3 (31973) in directory 31962.
File 31973 has been orphaned since all its filenames were invalid
Windows will recover the file in the orphan recovery phase.
Correcting minor file name errors in file 31973.
73 percent complete. (233642 of 245164 index entries processed)
Deleting index entry 01 Los Lonely Boys - Se?orita - www.file24ever.com.mp3 in i
ndex $I30 of file 31962.
Deleting index entry 12 Los Lonely Boys - La Contestaci?n - www.file24ever.com.m
p3 in index $I30 of file 31962.
245164 index entries processed.
Index verification completed.
CHKDSK is scanning unindexed files for reconnect to their original directory.
2 unindexed files scanned.
CHKDSK is recovering remaining unindexed files.
2 unindexed files recovered.
CHKDSK is verifying security descriptors (stage 3 of 3)...
231424 file SDs/SIDs processed.
Cleaning up 41 unused index entries from index $SII of file 9.
Cleaning up 41 unused index entries from index $SDH of file 9.
Cleaning up 41 unused security descriptors.
Security descriptor verification completed.
6871 data files processed.
CHKDSK is verifying Usn Journal...
1116928 USN bytes processed.
Usn Journal verification completed.
Correcting errors in the master file table's (MFT) BITMAP attribute.
Windows has made corrections to the file system.
244196000 KB total disk space.
158175168 KB in 30003 files.
22820 KB in 6873 indexes.
0 KB in bad sectors.
306168 KB in use by the system.
65536 KB occupied by the log file.
85691844 KB available on disk.
4096 bytes in each allocation unit.
61049000 total allocation units on disk.
21422961 allocation units available on disk.
E:\islag\Music\llb>dir
Volume in drive E is FreeAgent Drive
Volume Serial Number is 5038-892A
Directory of E:\islag\Music\llb
02/02/2011 12:18 PM <DIR> .
02/02/2011 12:18 PM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 87,743,979,520 bytes free
E:\islag\Music\llb>
Solution 4
Try specifying the UNC path (see Naming Files, Paths, and Namespaces). This gets around all sorts of restrictions. You would do it using the \\?\
syntax.
Example, if your file was on your desktop (and your Windows drive is C:), you can do
copy "\\?\C:\Users\codeLes\Desktop\Where Have All the Cowboys Gone?.ogg" "\\?\C:\Users\codeLes\Desktop\Where Have All the Cowboys Gone.ogg"
Note: You can't use relative paths with this syntax; you must specify the full path. And it does not work with the ren
command, but does work with copy
and move
.
Solution 5
chkdsk
will sometimes fix invalid file names. You will get a message about removing the file because all the file names are invalid, and then recovering a lost file. You can then find the file in C:\found.000\file0000.chk
. This is an effective way to remove the problem files, but not the best way if you want to keep them.
Related videos on Youtube
codeLes
Updated on September 17, 2022Comments
-
codeLes over 1 year
I have a song that Windows can't play because there is a question mark in the name of the file.
"Where Have All the Cowboys Gone?.ogg" // as an example
So I try to rename it and Windows complains whether I try it in Explorer or from command prompt.
Error I get when trying to copy, rename, or move is:
The Filename, directory name, or volume label syntax is incorrect
Is there a Windows way to force a rename in this case?
Update
I'll keep an eye on this question, but after 13 answers and many attempts (aside form 3rd party solutions) it seems that Windows can't do this (or at least my windows can't, no short names). So I'm accepting the answer which was my original solution anyway of using Linux. It would be nice to see Windows handle this somehow, so don't stop just because I've accepted this answer, the question still stands!
-
Admin over 14 yearsMay I ask how you got to this state? Windows generally won't let you do this.
-
Admin over 14 yearsand the answer is that I got the file from a Linux box. it's actually an .ogg file too. but I was wondering since I'm at work and haven't got my linux how to do it in windows... would be nice to know
-
Admin over 14 yearscan you open cmd.exe and show the output of the command "dir" in this folder? it might help to see how windows sees the name...
-
Admin over 14 yearsusing dir shows the file with it's name as I have it listed in the question...
-
Admin almost 12 yearsThe filesystem NTFS allows some characters that Windows doesn't. If Windows meets such files, it b0rks.
-
Admin over 7 yearsI once had a flashdrive go bad, chkdsk moved the files to a different sector but kept the damaged names which contained fun characters such as CRLF or even backspace. :)
-
Admin over 6 years@IvanChau: Not a duplicate. That other question is about a space in the name, which is, in fact, a piece of cake, unlike this one here (with a wildcard).
-
-
codeLes over 14 yearstried, no luck. "The Filename, directory name, or volume label syntax is incorrect"
-
codeLes over 14 yearsI don't have WinRAR at work and my work machine is not on the net. I do have 7zip, anyway I can do that with 7zip, just tried and it wouldn't let me add it to the archive... same error :-)
-
codeLes over 14 yearsdragging and dropping fails too with the same error... thanks though
-
codeLes over 14 yearstryijng your script nets me a "path not found" error (code: 800A004C). does it matter that this file is on an external USB drive? I put the file in the same folder... will try to hard code the entire file location next
-
codeLes over 14 yearsfully qualified name no work either...
-
Jhonny D. Cano -Leftware- over 14 yearsi agree up on the chkdsk option
-
RBerteig over 14 yearsSince generation of short names is optional depending on how Windows is currently configured, Murphy says that the OP has short names turned off and the file won't have one. To learn the short name if it is present for any file, use DIR/X which will add a column showing the short name for any file where it differs from the long name, if it has one at all. If there is a short name, this would be a plausible answer.
-
Ciaran over 14 yearsThe filename, directory name, or volume label syntax is incorrect.
-
codeLes over 14 yearsFrom home I use linux anyway... and the file is on a portable hard drive, I was just wondering if Windows could handle it... something like an <b>Sudo</b> windows command or something
-
salmonmoose over 14 yearsThis is a wildcard issue, not a permission issue. Under linux just about everything is a valid character in a filename (including linebreaks) under Windows, there's a set of reserved characters, and no effective way to escape them.
-
alex over 14 yearsYou really should give this a try... Short filenames can sometimes be useful.
-
Josh Hunt over 14 yearsMake sure the live CD distro has reliable NTFS support. I am not sure how it is going now, but I do remember it being a bit buggy a while back.
-
Atmocreations over 14 yearsrecent linux distros like ubuntu successfully support the most important features of NTFS.
-
codeLes over 14 yearsno short names, tried your example and also the dir/x proves that there aren't any listed.
-
codeLes over 14 yearsgave it a try, not luck "The filename, directory name, or volume label syntax is incorrect." Thanks! I'm getting to the point where I think the correct answer is to use Linux to rename it (which I have done).
-
pion over 14 yearsConversely you could try moving everything else out of the folder in question.
-
UNK over 14 yearsUbuntu 9.04 is absolutely flawless at NTFS support, with one or two annoyances (like if there's a power cut, and you boot into ubuntu to save a few seconds boot time, you can't access your windows partition until you boot back into it)
-
codeLes over 14 yearsi tried cygwin once on Vista, seemed to have the same issue, don't have access to it on my current work machine...
-
user14068 over 14 yearsI tried Directory Opus, and it didn't work (same error message).
-
user14068 over 14 yearsTried it with WinRAR. Didn't work. Same result.
-
JJ_Australia about 13 yearsGlobbing is done by the shell.
-
harrymc about 13 years@Hello71: Not in a DOS box, Linux boy.
-
Colonel Panic almost 12 yearsLinux NTFS support is perfect. It's better than Windows, for example, Linux can delete files with
:
in the name. -
Nicolas about 11 yearsIt worked for me with the
copy
command. -
Synetech almost 11 yearsActually, in this case, it should already work with the filename as is since the question-mark is a wildcard. No need for the asterisk this time.
-
Arjan over 10 yearsYou mean the file itself wasn't even in an archive, but you just used 7-Zip to rename it on the file system? Smart.
-
JulianHzg about 10 yearsI tried, cygwin wasn't able to delete the file ('No such file or directory'). Good idea though.
-
JulianHzg about 10 yearsSadly, that doesn't work, either with the original filename or with a more general wildcard like *.mp3.
-
JulianHzg about 10 yearsNice solution. Should work, but only works if the filename is longer than 8 characters (therefore not in my case).
-
rakensi almost 10 yearsThis works great. I tried several of the other options here, and this was the first one that worked.
-
Tanmay over 9 yearsI tried Flexible Renamer 8.4 which seems to do the trick. Sourced from the same website you mentioned.
-
Max over 9 yearsdoesn't work, tried on Win7 64b
-
Dasha about 9 yearsThis worked for me, or using the similar MSYS2 (a rewrite of MSYS, a fork of Cygwin) on Windows 8.1. I was able to mv the file to a new name and then delete it normally. My file had a space at the end, and it showed up using 'dir' - 'ls' didn't show it though.
-
enb081 almost 9 yearsWorked perfectly! This should be the answer.
-
Eryk Sun over 7 yearsThis answer is definitely wrong. The restriction on valid characters is in the NTFS driver in the Windows kernel.
\\?\
just bypasses file path processing in the user-mode runtime library. It doesn't allow opening filenames the contain the 5 wildcard characters ( *?"<> ), other reserved characters ( /|:\ ), or control characters. -
Eryk Sun over 7 years@bburns.km, at least you qualified your "works for me" statement. Of course it works for a filename with just a space at the end.
\\?\
would also work in this case -- when used properly with a Unicode, fully-qualified path. It's bypassing the user-mode runtime library code that emulates some quirky old MS-DOS rule from the 80s that ignores spaces at the end of names. The problem with invalid and reserved characters can't be addressed like this. -
Jim Balter over 7 years@enb081 No, this shouldn't be the answer, since it doesn't have anything to do with the question, which was how to rename the files. Sheesh.
-
Jim Balter over 7 years7zip was able to rename your file because filenames that end with spaces aren't a problem in Windows. Filenames containing '?' are a problem, and 7zip can't rename them.
-
user2284570 about 7 years
The filename is invalid or too long
-
Pacerier about 7 yearsDo you need to restart the Windows? Or can you run both concurrently and still manage to successfully delete the file with special character?
-
Pacerier about 7 yearsDoesn't work for me. My filename is
10:2
. -
salmonmoose about 7 years@Pacerier in theory, you possibly could, but it would mean you're mounting the drive in multiple operating systems concurrently, which is generally a bad idea. Shut down, and boot up in the new operating system.
-
Jesper about 7 yearsThis worked perfectly for me, because my problem turned out not to be actual question marks, but weird Unicode characters that just displayed as question marks in my file manager. By importing the files (there were hundreds) into a 7-Zip archive and then exporting them again, 7-Zip simply converted the bad characters to underscores (_). Then I was able to work with the files again. Problem completely solved. Thanks for an excellent tip!
-
leeand00 about 7 yearsI had a folder name with a
:
and doing this made the directory disappear. DON'T do this. -
leeand00 about 7 yearsActually,
chkdsk
moved the contents of the folder in the root directory of the hdd to a hidden folder and I was able to get my files back there see: superuser.com/a/320654/2293 -
user598527 about 7 yearsI can't rename files with ":" character: i.imgur.com/dZBqqeP.png
-
Dio Phung almost 7 yearsIt works in my case: I had a file name with Unicode character inside and with trailing
\n
. Don't ask me how do I created it (well, I'm trying to see if you can create multiple files with the identical name in Windows). Explorer, FreeCommander could not delete it but\\?\C:\...
can. -
Sz. over 6 years+1 for the correct (but more or less impractical) approach, hoping it'll bubble up a bit and overtake at least some of the wrong answers. ;)
-
Sz. over 6 yearsHuh? How are you supposed to move that file (of OP) with the wildcard in its name?
-
Sz. over 6 years@Nicolas, you mean there was a
?
or*
or<
or>
or:
in the name, andcopy
-ing just worked? (I just tried it and it didn't for me, unsurprisingly.) -
Sz. over 6 years@Pacerier: should be possible (and even safe) to mount the problematic dir from a VM running on the same host OS. A random example: howtogeek.com/187703/…
-
Nicolas over 6 years@Sz. sorry to heard it didn't work for you. I don't remember the filename I had to rename, but it worked for me with the
copy
command. Did you also trycygwin
and the bash commandmv
? -
Sz. over 6 years@Nicolas, thanks for trying to help, but my point is that those chars I listed above (and a few others, like
"
,|
,/
, and of course the backslash (which I can't seem to enter here :) )) are in a different class of problematic chars (reserved), and I'm afraid, neither thecopy
command norCygwin
can get round to renaming them. (You most likely had some different chars in your problematic filename.) -
salmonmoose over 6 years@Sz: That feels like you're expecting a lot from the Host OS - this would be relying on the VM to make calls to the host that the host may have problems with - it's this sort of behavior that leads to this sort of problem in the first place. Unless you're suggesting mounting the partition and letting the client do the work this feels like not a great idea ^TM
-
Marco van de Voort about 6 years7zip does work on files that end in a space, while windows explorer (and even a simple renamefile API call!) don't.
-
davidbak over 5 yearsThis simple trick just helped me. I had resigned myself to losing the file after chkdsk did its work but this answer reminded me about
\found.000
. -
علیرضا almost 5 yearsthank you. this is simple but effective way 👍
-
davidbak over 4 yearsWorked fine for a filename with an embedded
/n
which 7-zip couldn't manipulate. -
Juan C. Roldán over 4 yearsYou should advise that this will remove the files before showing the steps, or some unconcious user will delete them. A friend told me.
-
silicontrip over 3 yearsI've used this way to rename files with extra spaces on the end of their names. The most common source, I've seen, of invalid file characters are from Macs using an SMB share. And from archive files (zip) created on a non windows platform. NTFS can support more characters than Windows can. So I'll have to disagree with Eryk, as the NTFS driver seems to allow these filenames to be created.
-
SolarBear over 3 yearsFWIW this is the only solution that worked (easily) for me. I don't have admin rights on this PC so installing anything or using anything requiring admin privileges was not possible and I needed to remove a leftover file named
con
. I had MSYS2 on my machine and I could simplyrm
it. -
Bastian over 3 yearsNo, this does not work for file containing a
:
character. It saysmv: cannot stat 'Screenshot from 2015-10-11 21:29:26.png': No such file or directory
-
StayOnTarget over 3 yearsWorked great. I'd guess this would work with an iPhone also.
-
Luna about 3 yearsYou do not answer the question. Stack Exchange is not here for trolling ...