In short, I'm trying to use distutils.dir_util.copy_tree()
to copy data from an ext3 fs to a USB thumbdrive formatted using FAT32. The filenames tend to be long and contain interesting characters - which python strips/escapes fine for ext3. However, upon using copy_tree()
, the list of illegal characters suddenly grows as it gets thrown onto the FAT32 thumbdrive, which python doesn't escape and results in this:
IOError: [Errno 22] invalid mode ('wb') or filename: u'/media/usb0/data/someweirdfile.with.dots.etc?satellite=1'
Obviously mode wb
is fine, resulting in ?
being the illegal character. Short of re-writing copy_tree()
(or escaping the filename), is there any way to easily tell python that it's working on a different filesystem type?
No, Python does not know about the underlying filesystem (nor it should). It also doesn't escape anything in the filename — it's your job — ?
just happens to be a valid character for ext filesystems.