[Python-Dev] Unicode strings as filenames

Neil Hodgson nhodgson@bigpond.net.au
Fri, 4 Jan 2002 11:07:19 +1100


Martin:

> I agree this is unfortunate; patches are welcome. Please notice that
> the strategy of using wchar_t API on Windows has explicitly been
> considered and rejected, for the complexity of the code changes
> involved. So anybody proposing a patch would need to make it both
> useful, and easy to maintain. With these constraints, the current
> implementation is the best thing Mark could come up with.
>
> Software always has limitations, which are removed only if somebody is
> bothered so much as to change the software.

   Sure, I'm just putting my point of view which appears to be different
from most in that many developers just use a single locale. If I had a
larger supply of time then I'd eventually work on this but there are other
tasks that currently look like having more impact.

   The system provided scripting languages support wide character file
names. in VBScript:

Set fso = CreateObject("Scripting.FileSystemObject")
crlf = chr(13) & chr(10)
For Each f1 in fso.GetFolder("C:\").Files
 if instr(1, f1.name, ".htm") > 0 then
  s = s & f1.Path & crlf
  if left(f1.name, 1) = "z" then
   fo = fso.OpenTextFile(f1.Path).ReadAll()
   s = s & fo & crlf
  end if
 end if
Next
MsgBox s

   And Python with the win32 extensions can do the same using the
FileSystemObject:

# 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

   Neil