17

I've got a rather large number of files on my Windows drive that have a colon in their name. (These came from unpacking some Unix archives.)

When I try to delete them, Windows (XP) complains that the file does not exist, and refuses to delete it. This happens when trying to delete or rename it from explorer or the command line. Still, chkdsk does not complain about those files nor fix the problem.

Any ideas on how to get rid of them?

2
  • Will it let you rename them or move them to a different location? If you can move them, try putting them all in one directory, then deleting that directory.
    – nhinkle
    Jul 19, 2010 at 18:16
  • Technically, they are valid, it is Windows Explorer that is invalid^W special needs file manager. Jul 26, 2013 at 7:43

7 Answers 7

10

You may be able to use this syntax (per Microsoft KB 320081):

del "\\?\c:\path_to_file\bad:name.ext"

See also this serverfault question on the same topic, "delete file containing invalid characters in windows".

I think the old "ntfsdos" sysinternals utilities could remove/rename these files as well, but these are no longer available post-MS acquisition.

10
  • @Hello71 (to @Ruggle Humsteader) - new users can't comment, they can only answer (they presently need 50 rep points for that: superuser.com/faq ). They can comment on their own questions and answers, though. (Just so other new users aren't confused by your request.)
    – michael
    Mar 29, 2011 at 14:28
  • How would you make such a file from Windows?
    – cutrightjm
    Jul 26, 2013 at 4:29
  • @ekaj - the file could be created using another OS. Create a screenshot in Ubuntu, it has colons in the filename. Then open it in Windows - that won't work.
    – SPRBRN
    Jul 26, 2013 at 8:01
  • @rxt I'm aware. My point is if you can delete it, you can probably make it some how.
    – cutrightjm
    Jul 26, 2013 at 14:49
  • 3
    doesn't work for me in Windows 7
    – Populus
    Jan 25, 2014 at 23:35
8

You may want to try booting from an Ubuntu Live CD and deleting it from there.

1
  • Yesterday I saved a screenshot in Ubuntu, then tried to open that in a Windows VM. It refused to open, bad file type or something. Then I realised it could be the colon in the filename, which I couldn't remove in Windows. I change the name in Nautilus, and then I could open the file.
    – SPRBRN
    Jul 26, 2013 at 7:59
6

Close all the files, if any opened, that are saved in the drive which is containing such files. Now, Open the drive properties.

"My Computer" -> "Right Click on the this drive" > properties

Then, go to "Tools" tab and click "Check now" under 'Error checking' label.

[Click here for image]()

This will unmount your drive and will scan the complete drive for errors, eventually it will delete such files with illegal names. On finishing it will show a messages saying some files were fixed.

I successfully deleted such files from my external hard disk.

2
  • I wish it showed you a list of what it was going to fix, but this worked for me in Windows 8.1. Mar 2, 2015 at 23:40
  • first thing that helped me, after like 20 tries. This uses chkdsk which fixes lots of stuff.
    – oshell
    Dec 19, 2015 at 11:33
1

To fix this on Windows 7:

chkdsk C:/r
1
  • Thank you; this is the only option that worked for me. Nov 22, 2021 at 1:59
1

If everything else fails, you may need to edit the name directly in NTFS.

I've done it successfully with Active@ Disk Editor. Proceed with caution.

  • open the program
  • choose Explore My Computer
  • find your file
  • choose Inspect File Record on the button bar or in the context menu
  • enable Allow Edit Content in the Edit dropdown menu or in the context menu
  • find the name in the Unicode column and click on it, overwrite bad symbols with a good one, like a character or a dash. Remember what and how you renamed, you'll need it in the next step.
  • return to the My Computer tab
  • select file's parent directory in the tree view
  • choose Inspect File Record on the button bar or in the context menu
  • in the tree view on the left find Attribute $A0 (in bold), open it, find $INDEX_ALLOCATION, Data run, First cluster, click on the value, it should be interactive.
  • find the name and edit it in the same way as in the previous step. You may need to scroll down a bit to find it if there are many files in the directory.
  • if you're sure you didn't accidentally overwrite any other data, click Save. Otherwise, close the tab without saving the changes and carefully do everything again.
  • reboot.

If the file or directory is still inaccessible, try chkdsk now.

1
  • Thank you so much, it also worked perfectly on a bad folder name!
    – Berny23
    Jun 29, 2021 at 12:28
1

You can easily do it in the command line (CMD) without any fancy programs.

  1. Rename the file/folder using the old short notation (e.g. for Filename, FILENA~1) and. To get the notation, navigate to the directory containing the folder/file with an invalid name, and type:

    dir /x

  2. Rename to a valid name by using:

    ren FILENA~1 fileName

  3. Now erase the valid file/folder in either CMD or in Windows explorer:

    del fileName

-2

Another alternate that you may want to try is to bring in CygWin, a bash shell for windows. This would allow you to apply UNIX commands to your DOS folders.

4
  • 1
    If you regularly deal with unix files on a windows machine, it's always a good idea to have cygwin installed. Otherwise it might suit you better to boot and delete the file from a linux live CD when the situation arises. Jul 19, 2010 at 19:42
  • 6
    Unfortunately, I have tried cygwin, and that does not help. 8-{ Even cygwin is not able to remove the files. Jul 20, 2010 at 7:02
  • 7
    cygwin tools still relies on the windows API to delete files. If the Windows API refuses the filename, nothing can be done from Windows with standard file tools. I also recommend to access the filesystem from an alternate OS.
    – dolmen
    Mar 26, 2011 at 21:09
  • I've just tried accessing a file with colons on an ext3 drive with Cygwin and even that doesn't work.
    – laurent
    Nov 2, 2015 at 22:42

You must log in to answer this question.

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