Sometimes you cannot delete files on an NTFS file system, for example if the file contains a space at the beginning or end, or has a reserved name. Deleting the file gives an error: "The filename, directory name, or volume label syntax is incorrect.". Here's how to fix it: use "internal" commands.
The error in English and Dutch:
E:\Users\foobar>del "con.gif"
The filename, directory name, or volume label syntax is incorrect.
E:\Users\foobar>del "con.gif"
De syntaxis van de bestandsnaam, mapnaam of volumenaam is onjuist.
Another error message that often appears is: "The system cannot find the file specified.".
Remove undeletable files by using internal commands
You can delete files with a reserved name (all names listed below) using an internal command. This bypasses the check for reserved file names in the Win32 name space. To do this you have to work from the Windows command prompt (cmd.exe
), which you preferably start with administrative rights.
A number of examples:
E:\Users\foobar>del \\\?\c:\Users\foobar\con.gif
cd /d E:\Users\foobar\map1\map2\(....)\mapx
del \\\?\%CD%\con.gif
del \\\?\%CD%\lpt1.gif
In the case of files with spaces, you must use double quotes:
del "\\\?\C:\path\to\corrupt\file.ext "
Or you can also rename a file first:
C:\> rename \\.\C:\CON. deleteme
C:\> del deleteme
Reserved filenames on NTFS
Reserved file names on the NTFS file system are:
- CON
- PRN
- AUX
- NUL
- COM1
- COM2
- COM3
- COM4
- COM5
- COM6
- COM7
- COM8
- COM9
- LPT1
- LPT2
- LPT3
- LPT4
- LPT5
- LPT6
- LPT7
- LPT8
- LPT9
You can still delete these files by means of the above internal commands. See Microsoft's Naming Files, Paths, and Namespaces docs for more information.