It's not a device, it's a folder!
November 1, 2008 9:40 PM   Subscribe

How can I delete a folder in Windows that has a colon in the name?

While copying my music library back to my Windows machine (from previously being on Linux), I brought over a folder whose name contains a colon. Windows doesn't allow colons in file or folder names, so I don't know how this happened, but it did.

The problem is that I can't delete it. When I right-click and select delete or drag to the trash, Windows tells me "Cannot delete file: Cannot read from the source file or disk". It thinks I'm trying to specify a device, I think, because of the colon. In the Command Prompt I get the message "The filename, directory name, or volume label syntax is incorrect."

I can't rename the folder, either, or at least I don't know any other ways to do it than the ways that I've tried. I've tried wildcards in the Command Prompt.

Is there some trick that I don't know here? Or is there a character code that I can substitute or an escape character that I can prepend to the colon character in the Command Prompt? I know how to do this stuff in bash - what about Windows?
posted by dammitjim to Technology (27 answers total) 1 user marked this as a favorite
 
Well, if you want bash, you could install Cygwin and delete it in that.
posted by zsazsa at 9:42 PM on November 1, 2008


You can also try Unlocker, a free little download that works great.
posted by Justus at 9:53 PM on November 1, 2008


Have you tried quoting the folder name from the command prompt?
posted by jouke at 9:56 PM on November 1, 2008


Try deleting it from the command line, substituting ? for the colon.

cd \where\the\file\is
del abc?def.dat

Alternatively, try deleting using its short file name. Type dir /x to get a listing of short file names.
posted by zixyer at 10:02 PM on November 1, 2008


Response by poster: Well, if you want bash, you could install Cygwin and delete it in that.

That is true. If I can't get this done easily, I may resort to that. I've tried a couple of "bash on windows" exe's, but the PATH setup that they require is screwing me up.

Have you tried quoting the folder name from the command prompt?

Yeah, it does that automatically when you tab-autocomplete, which is a habit of mine from from bash.
posted by dammitjim at 10:03 PM on November 1, 2008


You don't say so, but did you try right-clicking the directory from Explorer and either choosing "rename" or "delete"?
posted by Class Goat at 10:05 PM on November 1, 2008


Response by poster: Try deleting it from the command line, substituting ? for the colon.

Hmm. This didn't work, but I wonder if it has to do with the fact that the folder also has spaces in the name, and so needs to be quoted on the command line. I tried both del and rmdir.

Alternatively, try deleting using its short file name. Type dir /x to get a listing of short file names.

dir /x gave me the exact same results as dir. Does that mean that there's no short file name?
posted by dammitjim at 10:10 PM on November 1, 2008


Response by poster: You don't say so, but did you try right-clicking the directory from Explorer and either choosing "rename" or "delete"?

Yep, tried both of those. Same "Cannot [rename/delete] file: Cannot read from the source file or disk" message as mentioned above.
posted by dammitjim at 10:11 PM on November 1, 2008


I feel bad for completely failing to read the question.

You can try a script like this. FileSystemObject might be use a different API than Explorer or rd. (save ending with .vbs and run it using cscript or just double-clicking)

Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFolder("C:\wherever\abc?def")
posted by zixyer at 10:13 PM on November 1, 2008


dir /x should give you an extra column in the output with the short file name. If the folder has fewer than eight characters in its name, it probably won't have a short file name. Did you try using wildcards for the spaces as well when you deleted the file?
posted by zixyer at 10:21 PM on November 1, 2008


Response by poster: @zixyer:
For the VBScript suggestion, I get a runtime error that says "Bad file name or number" with the code 800A0034. If I change the path in the script, I get a different message about a bad path, so I think it's finding the right directory but just not being about to do the right thing.

Regarding dir /x, i swear there's no appreciable difference in the results. dir /x gives the same results, but the column containing the filename strings is moved to the left like 12 columns or something in the terminal.

I did try wildcards, but I wonder if I tried all the possible permutations. I tried no quotes, with asterisks for all the spaces and for the colon. I tried just the first few letters of the folder and then one asterisk. Should I try question marks also?
posted by dammitjim at 10:29 PM on November 1, 2008


Wild cards in DOS can be strange. The theory is ? matches exactly one character and * matches zero or many characters, but it doesn't always work that way. Try replacing all spaces and the : with ? when you delete. Also, try scanning your disk for errors. You might actually have a filesystem issue.
posted by zixyer at 10:49 PM on November 1, 2008


Can you cut it and paste it on to a thumb drive? There, you can transport it back to the Linux system and rename it or you could delete it for good.
posted by nikkorizz at 12:19 AM on November 2, 2008


Could you show us what dir /x shows you?
posted by flabdablet at 12:58 AM on November 2, 2008


Does this utility help?
posted by randomstriker at 1:13 AM on November 2, 2008


You could also burn a Linux CD with NTFS read/write drivers, e.g. Trinity Rescue Kit, boot from it and try to delete the file that way.
posted by randomstriker at 1:17 AM on November 2, 2008


After a bit of fooling about with ntfs-3g on my Ubuntu box, I've found that ntfs-3g is quite capable of creating and using NTFS files with colons in their names. I imagine this is how your mystery file got created in the first place - you probably used Linux to do the original copying. Use Linux to rename or delete it as well. Any modern live CD should work if you don't still have a working Linux on that box.
posted by flabdablet at 1:17 AM on November 2, 2008


By the way, I suspect that the no-colon rule is buried deep enough in the guts of Windows that it won't matter what user interface you try. Anything that does its job by making Windows system calls will likely barf on a filename containing a colon.

CHKDSK might well spot the colon as a file system error and replace it, though.
posted by flabdablet at 1:23 AM on November 2, 2008


Try using the syntax

RD \\.\C:\somedir\some:folder
DEL \\.\C:\somedir\some:file

For the long filename/spaces you will need to either use the 8.3 equivalent or surround the whole string "with quotes"

The ? wildcard trick usually works for files, but RD does not support wildcards
posted by Lanark at 5:34 AM on November 2, 2008


A colon is used as the specifier for "Alternate Data Streams" on NTFS (kind of like the Resource Fork from the old Mac days). This means that any attempt to go through the Windows API will likely fail, so I think your best bet is to use a linux recovery live CD, and rename it from there.
posted by ArgentCorvid at 6:37 AM on November 2, 2008


Worse comes to worst, use Acronis True Image to back up everything but the file containing a colon, then reimage the drive from the backup. This worked to get rid of an undeletable file I had on my Web server once.
posted by kindall at 8:20 AM on November 2, 2008


Supposing the folder is on c:\documents\media\ and the directory you want to delete is called "music:funny", you can try this:


Move everything out of media that you want to keep. Move everything out of "music:funny" that you want to keep.

Open a command line and navigate to c:\documents\media\

cd \
cd documents
cd media

rmdir m*

This will remove all directories inside "media" that starts with "m". Should work. (The reason is that the folder might not actually have a colon in the name, but some kind of %20d sort of thing that just *looks* like a colon when you view it. Using the * wildcard lets the operating system figure out the real name and delete it.

Or yes, boot with a linux live cd and use that.
posted by gjc at 8:42 AM on November 2, 2008


Response by poster: Thanks everyone for your suggestions.

@gjc: yeah, I tried every possible wildcard combination I could think of, and it didn't work. I think it really IS a colon in the folder name. I don't know why Windows allowed me to copy it over.

@kindall: Nuke the site from orbit. Only way to be sure. I hope it doesn't come to that.

I think ArgentCorvid has it. I've downloaded an Ubuntu image and will be burning it when I have a chance tonight. Hopefully it will work - watch this space for updates!
posted by dammitjim at 10:13 AM on November 2, 2008


Did you use del or rmdir?
posted by gjc at 4:19 PM on November 2, 2008


what if you used the shortened DOS name? For example, if the folder is "dammitjim:music", try del dammit~1.
posted by niles at 5:21 PM on November 2, 2008


Knowledge base article Q320081 explains how to do this
see the sections:
Cause 5: The file name includes a reserved name in the Win32 name space
Cause 6: The file name includes an invalid name in the Win32 name space
posted by Lanark at 11:39 AM on November 3, 2008


Response by poster: Okay, OP back again finally. I tried the Command Line Jedi tricks that Lanark linked to in the Knowledge base article, but they didn't work for me either. I probably could have tried a zillion permutations of the command examples given there (and here), but since I'd already downloaded an Ubuntu image, I bailed on that.

Ubuntu, of course, worked. Boot the LiveCD, open the containing folder, change folder name. Reboot into Windows, and folder deletes easily.
posted by dammitjim at 4:55 AM on November 6, 2008


« Older Where do I go in NYC to cheaply replace my watch...   |   Disenfranchisement of the impatient Newer »
This thread is closed to new comments.