Unicode to DOS filenames (to call FSUM.exe)

DurumDara durumdara at gmail.com
Mon May 15 13:48:29 CEST 2006


John Machin írta:
> According to my reading of the source, the function you have called
> expects an 8-bit string.
> ====
> static PyObject *
> PyGetShortPathName(PyObject * self, PyObject * args)
> {
> 	char *path;
> 	if (!PyArg_ParseTuple(args, "s:GetShortPathName", &path))
> ====
> If it is given Unicode, PyArg_ParseTuple will attempt to encode it
> using the default encoding (ascii). Splat.
>
> Looks like you need a GetShortPathNameW() but it's not implemented.
> Raise it as an issue on the pywin32 sourceforge bug register. Tell Mark
> I sent you :-)
>
> It may be possible to fake up your default encoding to say cp1252 BUT
> take the advice of anyone who screams "Don't do that!" and in any case
> this wouldn't help you with a Russian, Chinese, etc etc filename.
>
> Another thought: try using ctypes.
>   

Hi !

I trying with that, but I get error, because the result is unicode 
too... :-(((

from ctypes import windll, create_unicode_buffer, sizeof, WinError
buf=create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(UFN,buf,sizeof(buf)):
    name=buf.value
    print [name]

######################################################
Commandline: C:\Python24\python.exe G:\SPEEDT~1\Module1.py
Workingdirectory: G:\speedtest
Timeout: 0 ms

[u'G:\\SPEEDT~1\\xA\xff']

Process "Pyhton Interpeter" terminated, ExitCode: 00000000
######################################################

 Can I do anything with this unicoded filename ? My code must be universal !

Thanx for help:
dd



More information about the Python-list mailing list