I have a function which needs to output a string containing a list of file paths. I can choose the separation character but I cannot change the data type (e.g. I cannot return a List<string> or something like that).

Wanting to use some well-established convention, my first intuition was to use the semicolon, similar to what Windows's PATH and Java's CLASSPATH (on Windows) environment variables do:


However, I was surprised to notice that ; is a valid character in an NTFS file name.

So, is the established best practice to

  • just ignore this fact (i.e. "no sane person should use ; in a file name and if they do, it's their own fault") or
  • is there some other established character for separating Windows paths or files? (The pipe (|) might be a good choice, but I have not seen it used anywhere yet for this purpose.)
  • 1
    Can you use a newline (\n) or does it have to be in a block?
    – Deco
    Oct 24 '12 at 7:58
  • @Deco: Good idea, haven't thought of that!
    – Heinzi
    Oct 24 '12 at 9:07
  • Another established convention is to enclose names with awkward characters in quotes, so your scanning routine can simply fetch all the chars in between without the need to check for separators. (This fails, of course, for names that contain quotes).
    – Mr Lister
    Oct 24 '12 at 9:19

| is one of the invalid filename/directory name characters and is frequently used as a separator, so it is a good choice for a separator of paths in a string.


Surprisingly, but |, <, and other symbols from the link provided by Oded are reserved characters only for CreateFile function and several other Windows APIs. Definitely, NTFS driver doesn't know about these restriction and allows to create file names with these symbols, which could be easily done for example in Linux using ntfs-3g driver+tools. In Windows also possible to create files with such names which would be not-deleted/readable/writable by ordinar API calls using low-level API or from kernel mode.

I suppose, the best alternative against using some esoteric separator would be using some serialization format like XML or json, which supported in many modern languages.

E.g. you data in json format will look like:


  • 1
    Fortunately, having to deal with such low-level file names is not a requirement in my case, but it's good to know nevertheless. Thanks and welcome to programmers.se!
    – Heinzi
    Oct 24 '12 at 10:11
  • Oh, the quadruple-backslash, how we love thee... Oct 24 '12 at 13:54
  • It's because of python default output:) Real string doesn't contain them.
    – dr.
    Oct 24 '12 at 19:56

The windows PATH setting uses semicolons (;). Seems like that might be a good standard to follow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.