Unicode to DOS filenames (to call FSUM.exe)
DurumDara
durumdara at gmail.com
Mon May 15 08:01:58 EDT 2006
John Machin írta:
> 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 :-)
> Another thought: try using ctypes.
>
Hi !
It seems to be I found a solution. A little tricky, but it is working:
#####################################################################
import sys,os
from sys import argv as sysargv
UFN=u'%s\\xA\xff'%os.getcwd()
if os.path.exists(UFN):
os.remove(UFN)
f=open(UFN,'w')
f.write('%s\n'%('='*80))
f.close()
from ctypes import windll, create_unicode_buffer, sizeof, WinError
buf=create_unicode_buffer(512)
if windll.kernel32.GetShortPathNameW(UFN,buf,sizeof(buf)):
fname=buf.value
#import win32api
#dfn=win32api.GetShortPathName(name)
#print dfn
else:
raise
shortpath,filename=os.path.split(fname)
import win32file
filedatas=win32file.FindFilesW(fname)
fd=filedatas[0]
shortfilename=fd[9] or fd[8]
shortfilepath=os.path.join(shortpath,shortfilename)
print [UFN]
print shortfilepath
f=open(shortfilepath,'r')
print f.read()
sys.exit()
But I don't understand: why the shortpathw not convert the filename too
(like dir) ?
Thanx for help:
dd
More information about the Python-list
mailing list