On 08/06/2013 17:53, Νικόλαος Κούρας wrote:
Sorry for th delay guys, was busy with other thigns today and i am still 
reading your resposes, still ahvent rewad them all just Cameron's:

Here is what i have now following Cameron's advices:


#========================================================
# Collect filenames of the path directory as bytes
path = b'/home/nikos/public_html/data/apps/'
filenames_bytes = os.listdir( path )

for filename_bytes in filenames_bytes:
        try:
                filename = filename_bytes.decode('utf-8)
        except UnicodeDecodeError:
                # Since its not a utf8 bytestring then its for sure a greek 
bytestring

                # Prepare arguments for rename to happen
                utf8_filename = filename_bytes.encode('utf-8')
                greek_filename = filename_bytes.encode('iso-8859-7')
                
                utf8_path = path + utf8_filename
                greek_path = path + greek_filename
                
                # Rename current filename from greek bytes --> utf8 bytes
                os.rename( greek_path, utf8_path )
==========================================

I know this is wrong though.

Yet you did it anyway!

Since filename_bytes is the current filename encoded as utf8 or greek-iso
then i cannot just *encode* what is already encoded by doing this:

utf8_filename = filename_bytes.encode('utf-8')
greek_filename = filename_bytes.encode('iso-8859-7')

Try reading and understanding the code I originally posted.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to