I recently zipped up a number of files created by a script I wrote and sent them to a Windows-using colleague. He could not unzip the archive, since some of my filenames contained a :
which isn’t legal on Windows.
It’s trivial to strip out the :
, but what if there are other characters that I’m unaware of as being illegal in Windows path/filenames?
I wondered whether pathlib
’s “pure” path objects would flag illegal characters in any way, but they do not as far as I can determine:
>>> from pathlib import PurePosixPath, PureWindowsPath
>>> pp = PurePosixPath("foo/bar:baz.txt")
>>> wp = PureWindowsPath(pp)
>>> print(wp)
foo\bar:baz.txt
Given that I do not have easy access to a Windows machine for testing, is there a simple way to ensure path/filenames generated by Python are “Windows-safe”?