14

It is often convenient to name files and folders with a date and time, such as standard ISO 8601 format: 2014-12-10T22:35:28.460Z.

Unfortunately, the Mac’s HFS+ file system uses the COLON as a path separator just as Unix-like OSes use SOLIDUS / (slash) and Microsoft OSes use REVERSE SOLIDUS \ (backslash). All three characters must be avoided when naming a file or folder for compatibility.

What character might be commonly used as a replacement for the COLON?

  • Using a HYPHEN - makes it tricky to programmatically reverse the conversion to standard format.
  • Similarly, using a FULL STOP . (period) makes reverse conversion difficult as they will be misinterpreted as fractional seconds.

For example, when programming in Java 8 on OS X Mountain Lion, calling File::mkdir() for string 2014-12-11T21:33:08 results in a folder named 2014-12-11T21/33/08.

7
  • 3
    Pretty much all modern file systems support spaces in file names. Also, if readability isn't a concern why not just eliminate the offending characters and use a set format, ex.:YYYYMMDDTHHMMSSZ.
    – Brian Duke
    Commented Dec 10, 2014 at 23:48
  • Why not just use the : it seems to work OK from the shell. I suspect only OS<=9 and classic have an issue with : so nowadays is an issue. AL:so MS OSes can use / as a directory split
    – mmmmmm
    Commented Dec 11, 2014 at 0:31
  • @Mark Modern versions of the Finder may handle a colon. But during programmatic access, problems ensue. Commented Dec 11, 2014 at 0:52
  • I've never had any trouble accessing a file with a colon in the name. It just looks weird from Finder, since it's switched to a slash.
    – 0942v8653
    Commented Dec 11, 2014 at 2:59
  • 2
    Specifically, HFS+ allows filenames to contain / but not colon. When in Terminal (or anywhere the filesystem is accessed using the POSIX API instead of the Macintosh API), the / in the name as stored on disk is translated to : in RAM, and : in RAM is translated back to / as a new filename is stored in the catalog. Programs using the traditional Macintosh API are not affected, and see the / just as it appears on disk. This way each API has only a single forbidden character (well, two if you count NUL) and only a single filename separator, without interfering with each other.
    – ganbustein
    Commented Dec 11, 2014 at 3:27

4 Answers 4

8

ISO 8601 “Basic” variation

You can avoid using the colon by employing ISO 8601 “basic” format strings (YYYYMMDDTHHMMSSZ) for naming files and folders. The standard allows for the separators to be omitted from the YYYY-MM-DDTHH:MM:SSZ format.

So both of these examples are valid under the standard:

2016-03-27T07:01:02Z

20160327T070102Z

If you need to process those strings with certain programming or scripting languages then maybe you have to convert them to the extended format that incorporates separators (hyphens, colons) and time zone info.

International standard date and time notation - "If a date and a time value are stored together in a single data field, then ISO 8601 suggests that they should be separated by a latin capital letter T, as in 19951231T235959". So the T in the middle is optional (19951231235959) but suggested.

1
  • Good solution. Indeed the better date-time libraries such as the java.time framework built into Java 8 and later as well as Joda-Time have no problem parsing either the “basic” format or the longer format containing separators. Commented Mar 28, 2016 at 1:30
7

The raised colon, Unicode 0x02F8 ( raised colon ˸ vs colon : ) would not be interpreted as a separator by Finder or other scripts. (More info about the raised colon here: http://www.charbase.com/02f8-unicode-modifier-letter-raised-colon )

The way to enter that character varies, depending on your OS X version. More details can be found at Apple's support page: http://support.apple.com/en-us/HT201586

1
  • 3
    Interesting idea. This answer is almost too clever. Looking so much like the regular COLON might cause confusing when parsing. Commented Dec 11, 2014 at 4:27
6

I've investigated this too. Most of the alternative glyphs with the word 'colon' in the description are decidedly unattractive as a colon replacement (˸, ܄, , , , , and ).

There is another alternative that at least has a similar character width to the original colon - the mathematical symbol for a ratio: . It looks great in a number of monospaced fonts, but it is a little small in the default MacOS system font.

Here it is being used in a file name:

/Users/me/Books/Book Title: Book Subtitle.pdf [restricted colon glyph]

/Users/me/Books/Book Title∶ Book Subtitle.pdf [permitted ratio glyph]

1
  • Thanks for the comprehensive list! Also very interesting alternative is mentioned by @rocky – the Hebrew punctuation symbol Sof Pasuq: compart.com/en/unicode/U+05C3
    – saulius2
    Commented Feb 1, 2023 at 12:17
1

The Hebrew punctuation ׃ works great for me ... unicode 05C3 ...

2
  • 3
    watch out, that Hebrew colon can really mess things up when adjacent to numbers! Try typing 1 (Hebrew colon) 2. It renders backwards as 2:1! Something to with Hebrew right-to-left direction. Anyways, it would be extremely confusing if trying to use with left-to-right languages.
    – wisbucky
    Commented Apr 3, 2017 at 6:46
  • 1
    Yea that's probably not a great alternative if text renderers try to switch to RTL mode when they encounter this character :(
    – Matt M.
    Commented Jun 16, 2019 at 18:40

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