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:
C:somedirsomefile.txt;C:someotherdirsomeotherfile.txt
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.)
3
|
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:
[“C:somedirsomefile.txt”,C:someotherdirsomeotherfile.txt”]
3
The windows PATH setting uses semicolons (;
). Seems like that might be a good standard to follow.