Problem in accessing files with unicode fonts.

venutaurus539 at gmail.com venutaurus539 at gmail.com
Tue Feb 24 10:18:41 CET 2009


On Feb 24, 1:44 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Tue, 24 Feb 2009 05:15:33 -0200, venu madhav <venutaurus... at gmail.com>  
> escribió:
>
>
>
> >> > def findFile(dir_path):
> >> >     for name in os.listdir(dir_path):
> >> >         full_path = os.path.join(dir_path, name)
> >> >         print full_path
> >> >         if os.path.isdir(full_path):
> >> >             findFile(full_path)
> >> >         else:
> >> >             v = unicode(full_path,errors='skip')
> >> >             i = win32api.GetFileAttributes(v)
>
> >> > findFile("F:\\DataSet\\Unicode")
> >> > ---------------------------------------------------------------
> >> > Now when I run this scirpt, the full_path variable which should  
> >> contain
> >> the
> >> > name of the file has "????" for non english ( I tried Arabic)  
> >> characters.
> >> As
> >> > a result the getfileattributes function is failing to recognise that  
> >> file
> >> > and is raising an exception.
> >> >     i = win32api.GetFileAttributes(v)
> >> > error: (123, 'GetFileAttributes', 'The filename, directory name, or
> >> volume
> >> > label syntax is incorrect.')
>
> If you call os.listdir with an unicode directory, it returns unicode file  
> names.
> That is (after correcting the previous error in findFile), call it using:
> findFile(u"F:\\DataSet\\Unicode")
>
> --
> Gabriel Genellina

Thank you for your solution. It really helped. But how should I give
if my path is in a varialble.

For ex: path has that value obtained through command line arguments.

path = sys.argv[2]

In such a case how can we convert the path to UNICODE?

Thank you once again,
Venu








More information about the Python-list mailing list