Unicode Chars in Windows Path

Marko Rauhamaa marko at pacujo.net
Thu Apr 3 05:00:09 EDT 2014


Chris Angelico <rosuav at gmail.com>:

> Small clarification: The Windows *API* accepts both types of slash
> (you can open a file using forward slashes, for instance), but not all
> Windows *applications* are aware of this (generally only
> cross-platform ones take notice of this), and most Windows *users*
> prefer backslashes. So when you come to display a Windows path, you
> may want to convert to backslashes. But that's for display.

Didn't know that. More importantly, I had thought forward slashes were
valid file basename characters, but Windows is surprisingly strict about
that:

   < > : " / \ | ? * NUL

are not allowed in basenames. Unix/linux disallows only:

  / NUL

In fact, proper dealing with punctuation in pathnames is one of the main
reasons to migrate to Python from bash. Even if it is often possible to
write bash scripts that handle arbitrary pathnames correctly, few script
writers are pedantic enough to do it properly. For example, newlines in
filenames are bound to confuse 99.9% of bash scripts.


Marko



More information about the Python-list mailing list