2

Possible Duplicate:
How to force Windows XP to rename a file with a special character?

I have a few files whose names have characters such as "?" and ":" that are forbidden by windows. I'm not sure how they managed to get there with these names, since I can't manually create files with these names. They're recovered from an HFS drive, but the tool that recovered them was running under windows and so should have been subject to the same restrictions while creating them, I would think.

Anyway... now that they're here, I can open them, but I can't move, copy, rename, or delete them. I want to delete a few of them, but most I want to save and copy to another drive. How might I go about this?

1

6 Answers 6

5

You cannot delete a file or a folder on an NTFS file system volume

Cause 5: The file name includes a reserved name in the Win32 name space If the file name includes a reserved name (for example, "lpt1") in the Win32 name space, you may not be able to delete the file. To resolve this issue, use a non-Win32 program to rename the file. You can use a POSIX tool or any other tool that uses the appropriate internal syntax to use the file.

Additionally, you may be able to use some built-in commands to bypass the typical Win32 reserved name checks if you use a particular syntax to specify the path of the file. For example, if you use the Del command in Windows XP, you can delete a file named "lpt1" if you specify the full path of the file by using the following special syntax:

del \\?\c:\path_to_file\lpt1

For more information about deleting files with reserved names under Windows NT and Windows 2000, click the following article number to view the article in the Microsoft Knowledge Base:

120716 How to remove files with reserved names in Windows

For more information about deleting files with reserved names under Windows XP, click the following article number to view the article in the Microsoft Knowledge Base:

315226 How to remove files with reserved names in Windows XP

If you open a handle to a file by using the typical Win32 CreateFile mechanism, certain file names are reserved for old-style DOS devices. For backward compatibility, these file names are not permitted and they cannot be created by using typical Win32 file calls. However, this issue is not a limitation of NTFS.

You may be able to use a Win32 program to bypass the typical name checks that are performed when a file is created (or deleted) by using the same technique that you use to traverse folders that are deeper than MAX_PATH. Additionally, some POSIX tools are not subject to these name checks.

Cause 6: The file name includes an invalid name in the Win32 name space You may not be able to delete a file if the file name includes an invalid name (for example, the file name has a trailing space or a trailing period or the file name is made up of a space only). To resolve this issue, use a tool that uses the appropriate internal syntax to delete the file. You can use the "\?\" syntax with some tools to operate on these files, for example:

del "\\?\c:\path_to_file_that contains a trailing space.txt "

The cause of this issue is similar to Cause 4. However, if you use typical Win32 syntax to open a file that has trailing spaces or trailing periods in its name, the trailing spaces or periods are stripped before the actual file is opened. Therefore, if you have two files in the same folder named "AFile.txt" and "AFile.txt " (note the space after the file name), if you try to open the second file by using standard Win32 calls, you open the first file instead. Similarly, if you have a file whose name is just " " (a space character) and you try to open it by using standard Win32 calls, you open the file's parent folder instead. In this situation, if you try to change security settings on these files, you either may not be able to do this or you may unexpectedly change the settings on different files. If this behavior occurs, you may think that you have permission to a file that actually has a restrictive ACL.

3
  • Unfortunately, neither of these causes (nor the others described in the linked article) precisely describe this condition. I tried the "\\?\" technique. I also tried using using "rm" and "mv" from cygwin, which I assume fall under the category of "non-Win32 programs." None of those worked.
    – Josh
    Jan 2, 2010 at 1:49
  • there's MacNames (but $169 is quite a steep price :) peccatte.karefil.com/software/MacNames/MacNamesEN.htm
    – Molly7244
    Jan 2, 2010 at 2:02
  • @josh: cygwin falls under the category of "win32 programs"; it translates the unix system calls that rm and mv use into win32 equivalents. Jan 2, 2010 at 2:05
2

From my answer to a similar question:

Failsafe Method:

Boot to a Linux LiveCD. Ubuntu has good NTFS support, and Linux handles a lot more wonky-characters-in-filenames than Windows. The perl rename script may be included as the system's rename command, which is handy for batch-modifying many similarly-named files.


In Windows Command Shell with Short Filenames

The DOS command DIR/X shows short filenames, if they exist on your system.

$ cmd
c:\test> dir /x
 Volume in drive E is NUVOL
 Volume Serial Number is 80D3-A96D

 Directory of e:\tor\test

10/04/2009  05:15 AM    <DIR>                       .
10/04/2009  05:15 AM    <DIR>                       ..
10/04/2009  05:11 AM                 0 CLIP-2~1.MOV clip-2009-10-01 21;26;00.mov
               1 File(s)              0 bytes
               2 Dir(s)   5,201,670,144 bytes free

If they do exist, the REN command will move them to a new name; the new name can be a new (valid) long filename.

c:\test> ren CLIP-2~1.MOV "clip-2009-10-01_21-26-00.mov"

That's how to fix one.

To batch process all of them, you need to 1) grab the short filenames of all the files you want to move; 2) convert your listing into a batch file with the appropriate REN commands; and 3) run the resulting batch script. If you are comfortable with perl (or sed/awk, python, whatever), you can script this yourself, or you can craft it by hand from the listing you made in step 1.

But if DIR/X doesn't show the short filenames, your system has them disabled, and this solution won't help.

0

If Idigas' suggestion does not work, you could always move them with a Linux LiveCD such as Ubuntu. It allows question marks and colons in filenames so it should have no problem handling the files.

You just need to mount your drive first. If XP is your only operating system installed on the disk, it can probably be mounted from /dev/sda1 or /dev/hda1 depending on if it's a SCSI drive or IDE drive.

to mount a SCSI drive (if running NTFS):

mount -t ntfs-3g /dev/sda1 /mnt

to mount an IDE drive (running NTFS):

mount -t ntfs-3f /dev/hda1 /mnt

If it's a FAT32 volume, you can use vfat as the type (-t vfat)

2
  • I might have to resort to this. Unfortunately many Linux distros don't seem to like my box; I'm not sure why but I've often had to do lots of fiddling in the past to get it to boot, and I don't want to go through that again until I run out of other ideas.
    – Josh
    Jan 2, 2010 at 1:52
  • Trouble trying to boot from the CD? Wubi has you covered ( wubi-installer.org ). You can install Ubuntu from inside Windows, then when you're done with it, uninstall it like a regular app from add/remove programs!
    – user1931
    Jan 2, 2010 at 1:57
0

Try Delete Doctor (freeware) or delinvfiles (shareware, but have more features) to delete the file with its short or UNC name

0

I've used Windows Services for Unix to remove these sorts of files in the past.

The reason that such files can be created is that Windows has support for POSIX, so NTFS was designed to be able to support all the features of POSIX filesystems. However, normal Win32/Win64 programs, which are using the regular Windows API, can't access these features. You need to use a program written to the native API or the POSIX api to create or remove such files.

-1

For some reason, I usually have more luck when moving/copying/renaming/(anything really) files from the command line, than when doing it windows explorer.

Not the answer you're looking for? Browse other questions tagged .