Saving (unusual) linux filenames
nobody at nowhere.com
Tue Aug 31 20:33:26 CEST 2010
On Tue, 31 Aug 2010 18:13:44 +0100, MRAB wrote:
>>>> this works for "normal" paths but as soon as i have a path that does
>>>> include a "," it breaks. The problem now is that (afaik) linux allows
>>>> every char (aside from "/" and null) to be used in filenames. The only
>>>> solution i can think of is using null as a seperator, but there have to
>>>> a cleaner version ?
>>> You could use a tab character '\t' instead.
>> That just breaks with a different set of filenames.
> How many filenames contain control characters? Surely that's a bad idea.
It may be a bad idea, but it's permitted by the OS. If you're writing a
general-purpose tool, having it flake out whenever it encounters an
"unusual" filename is also a bad idea.
FWIW, my usual solution is URL-encoding (i.e. replacing any "awkward"
character by a "%" followed by two hex digits representing the byte's
value). It has the advantage that you can extend the set of bytes which
need encoding as needed without having to change the code (e.g. you can
provide a command-line argument or configuration file setting which
specifies which bytes need to be encoded).
More information about the Python-list