8

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.

  • 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 Dec 10 '14 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 – Mark Dec 11 '14 at 0:31
  • @Mark Modern versions of the Finder may handle a colon. But during programmatic access, problems ensue. – Basil Bourque Dec 11 '14 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 Dec 11 '14 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 Dec 11 '14 at 3:27
6

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.

  • 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. – Basil Bourque Mar 28 '16 at 1:30
2

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

  • 3
    Interesting idea. This answer is almost too clever. Looking so much like the regular COLON might cause confusing when parsing. – Basil Bourque Dec 11 '14 at 4:27
0

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

  • 2
    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 Apr 3 '17 at 6:46
  • Yea that's probably not a great alternative if text renderers try to switch to RTL mode when they encounter this character :( – Matt M. Jun 16 at 18:40

You must log in to answer this question.

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