[Tutor] os.rename anomaly in Python 2.3 on Windows XP

Tony Cappellini cappy2112 at gmail.com
Mon Oct 8 22:57:00 CEST 2007


Using Windows XP, SP2 and Python 2.3

I've written a script which walks through a bunch of directories and
replaces characters which are typically illegals as filenames, with an
'_' character.

The directories are part of a package of software which is released by
a group of people from Japan, and as such, they use their own
character set (probably Kanji). However, most of the time, there are
only 1 or 2 directories with unknown or illegal characters, as
determined by
my system (which does not use the Kanji characters).

When my script encounters a directory with the unwanted characters,
it's easy to detect them and filter them out. The next step is to
rename the file to get rid of the problem characters.

However, recently when I called os.rename(oldname, newname) an OS
exception was thrown with "Illegal filename". I was able to narrow it
down to oldname being the cause of the problem.
Some of the characters showed up as ? in the Python strings.

Oddly enough, os.rename() cannot perform the renaming of the
directories, but I can do this manually in File Explorer or even in a
CMD console using "rename"

So what is os.renaming() actually calling on a Windows system, that
won't allow me to rename dirs with illegal characters?


More information about the Tutor mailing list