59

I am getting errors from customers who are uploading files with a colon in the file name, i.e. C:/uploads/test : doc.html

I assume that some Unix or Linux system is generating the file but I'm not sure how the users are saving them with the invalid filename. I have coded a piece that should rename the document on upload. My problem is that I can't test it because I can't get a file on Windows that has a colon in the filename.

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
David
  • 709
  • 1
  • 5
  • 6
  • 11
    There are a few characters that simply aren't allowed in Windows filenames, the colon is one of them. Sorry. – Mark Ransom Apr 30 '12 at 15:46
  • 8
    P.S. the full list of invalid characters is here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#file_and_directory_names – Mark Ransom Apr 30 '12 at 16:14
  • 2
    It might be possible to do this with the native API or from a device driver. But you wouldn't be able to upload the file from a Windows application, or indeed do anything else with it. – Harry Johnston Apr 30 '12 at 21:09
  • 8
    I often use fullwidth colon `:` in my file names. It's a Unicode character that looks very much like a colon so I use it where Windows won't allow the usual colon. It's visually surrounded by spaces that you can't remove. I stumbled upon it ages ago, now I just copy and paste it whenever I need it. – adraedin Jul 24 '14 at 23:11

7 Answers7

107

I found a very similar character to a colon, "꞉" it is a unicode character called a Modifier Letter Colon. This has no space like the fullwidth colon and is pretty much exactly the same as a regular colon but the symbol works. You can either copy and paste it from above or you can use the code point, U+A789

Jack
  • 1,248
  • 1
  • 9
  • 12
  • 9
    Awesome. I've been tracking down these unicode replacements for filenames for a while now, so thank you! You are awesome. I know you didn't ask but, for what it's worth, if you ever need a question mark you can use '⁇' instead. (U+2047). For slashes you can use the division slash: '∕' (U+2215). Maybe someone will find those useful. – Brent Rittenhouse May 20 '18 at 09:32
21

A colon is an invalid character for a Windows file name. You won't be able to allow ':' in the file name, but you can work around it.

You can either do what it sounds like you have already done; create a script that replaces these invalid characters with valid ones on the UNIX side. Or, you can take care of this on the Windows server with File Name Character Translation: http://support.microsoft.com/kb/289627

Andrew D. Bond
  • 902
  • 1
  • 11
  • 11
Mike
  • 359
  • 1
  • 3
  • 1
    I believe I have solved the problem by renaming file uploads on the fly, but I need to somehow get a file onto a windows machine with a colon in the file name. Our customers are somehow doing it so it must be possible. – David Apr 30 '12 at 19:21
  • @David: what makes you think your customers are doing this? Are you sure the uploads are coming from Windows machines? – Harry Johnston Apr 30 '12 at 21:09
  • 1
    Be careful - you *can* create something called FOO:BAR, but what you've got then is a file named FOO containing a data stream named BAR (as well as the unnamed data stream). In a directory listing you'll just see FOO. – dave Apr 30 '12 at 23:35
  • I am getting error reporting with the attempted upload file name. I have confirmed that at least some of the attempted uploads were from windows machines. – David May 01 '12 at 01:16
  • 1
    I know is not intended but i somehow need to verify that my solution fixed the issue. How would I go about creating a file named foo:bar? – David May 01 '12 at 01:18
8

Other replacements I've found for reserved characters are

” ‹ › ⁎ ∕ ⑊ \︖ ꞉ ⏐

For example in python you could do:

fixed_name = orig_name.replace('\\\\','⑊')
forbidden_characters = '"*/:<>?\|'
unicode_characters = '”⁎∕꞉‹›︖\⏐'
for a, b in zip(forbidden_characters, unicode_characters):
    fixed_name = fixed_name.replace(a, b)
aljgom
  • 7,879
  • 3
  • 33
  • 28
  • `man 8 ntfs-3g` states: `The forbidden characters are the nine characters " * / : < > ? \ |`. I count 10 in your answer, what is this one for: `⑊` ? – malat Nov 22 '20 at 17:24
  • 1
    @malat in that case it's not one character, it would be replacing two characters `\\ ` with one character that looks similar `⑊`, because replacing it with 2 of the replacement one-character backslashes would look like this `\\` – aljgom Nov 24 '20 at 10:40
6

It's probable from the filename you provided that the character you have in your filenames is not a literal colon :, which is a reserved character in Windows filenames, but a fullwidth colon Instead. It's a Unicode character that looks very much like a colon, visually surrounded by spaces that you can't remove. You can handle it the very same way as any Unicode chacter, the code point is U+FF1A.

adraedin
  • 69
  • 1
  • 1
  • 1
    this does not address the OPs question; while the advice is very good, you should either place this in a comment to question *or* ask/answer this in Q&A style as in Jeopardy, first asking "How to use colon in Windows filenames?" question, selecting Q&A style answer and providing this info there. –  Jul 24 '14 at 23:39
  • 3
    @vaxquis: on the contrary, I think it likely that this was indeed the cause of the OP's problem; he thought the filenames he was trying to deal with had colons in them, but they were probably fullwidth colons. – Harry Johnston Jul 26 '14 at 02:19
  • 1
    @HarryJohnston in that case, I'm editing the question to explicitly include this information –  Jul 26 '14 at 12:21
2

You can use the CJK(Chinese/Japan/Korean) one

":"

which is pretty generic.

imoc
  • 25
  • 3
-1

Currently, you would use WSL, url for instructions: https://learn.microsoft.com/en-us/windows/wsl/install-win10.

You could then create a colon in your Linux Distro.

KetZoomer
  • 2,701
  • 3
  • 15
  • 43
-2

HOW TO NAME A FILE OR FOLDER USING A SYMBOL THAT LOOKS LIKE A COLON

In the example below, the font size is 12, with the exception of the symbol, which is set to Subscript, Bold and a font size of 16. The character code for the colon-like symbol is 02F8.

The reason for the Subscript setting is to position the symbol lower relative to its vertical position. The bold and larger font settings are applied so that the symbol is more discernible on the page, and have no affect when used in a file or folder name.

Example: (C˸) Symbol – Subscript, Calibri, Bold and font size of 16.

*Using Windows 7, and Word 2007

Jeff
  • 1