First of all thank you for helping me MRAB.
After make some alternation to your code ia have this:

----------------------------------------
# Give the path as a bytestring so that we'll get the filenames as bytestrings
path = b"/home/nikos/public_html/data/apps/" 

# Setting TESTING to True will make it print out what renamings it will do, but 
not actually do them
TESTING = True 

# Walk through the files. 
for root, dirs, files in os.walk( path ): 
        for filename in files: 
                try: 
                        # Is this name encoded in UTF-8? 
                        filename.decode('utf-8') 
                except UnicodeDecodeError: 
                        # Decoding from UTF-8 failed, which means that the name 
is not valid UTF-8
                        # It appears that the filenames are encoded in 
ISO-8859-7, so decode from that and re-encode to UTF-8
                        new_filename = 
filename.decode('iso-8859-7').encode('utf-8') 

                        old_path = os.path.join(root, filename) 
                        new_path = os.path.join(root, new_filename)
                        if TESTING:
                                print( '''<br>Will rename {!r} ---> 
{!r}<br><br>'''.format( old_path, new_path ) )
                        else: 
                                print( '''<br>Renaming {!r} ---> 
{!r}<br><br>'''.format( old_path, new_path ) )
                                os.rename( old_path, new_path )
sys.exit(0)
-------------------------

and the output can be seen here: http://superhost.gr/cgi-bin/files.py

We are in test mode so i dont know if when renaming actually take place what 
the encodings will be.

Shall i switch off test mode and try it for real?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to