Unicode filenames and os.path.* functions

Neil Hodgson nhodgson at bigpond.net.au
Fri Jan 4 06:16:10 EST 2002


Alex Martelli:
> "Michael Ebert" ...

> > Is there a Unicode supporting file operation library?
>
> I believe Mark Hammon's "win32all" extensions accept Unicode strings
> (in particular as filenames and paths) and give you access to all of
> the Win32 API file-related functionality.

   I've been doing a bit of whinging on python-dev today about this.

   As well as using the win32file module, you can also use the
FileSystemObject available with recent versions of Windows for a more
object-oriented API:

# encode used here just to make things print as a quick demo
import win32com
fso = win32com.client.Dispatch("Scripting.FileSystemObject")
s = ""
fol = fso.GetFolder("C:\\")
for f1 in fol.Files:
 if f1.name.find(".htm") > 0:
  s += f1.Path.encode("UTF-8") + "\r\n"
  if f1.name[0] == u"z":
   fo = fso.OpenTextFile(f1.Path).ReadAll()
   s += fo.encode("UTF-8") + "\r\n"
print s

   This API was provided for VBScript and JScript and documentation is
available from
http://msdn.microsoft.com/scripting

   Neil





More information about the Python-list mailing list