Tony Cappellini wrote: > 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? > Sounds like it has something to do with Unicode. Your filenames aren't being interpreted correctly. Perhaps os.listdir is giving you the UTF-8 versions rather than the Unicode versions of the filenames? -Luke > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor