[python-win32] win32file.CreateFile versus win32file.CreateFileW
Scott Leerssen
sleerssen at gmail.com
Mon Feb 6 17:21:39 CET 2012
On Feb 6, 2012, at 11:03 AM, Amaury Forgeot d'Arc wrote:
> 2012/2/6 Scott Leerssen <sleerssen at gmail.com>
> I'm trying to open files with names that contain Japanese characters, and found that win32file.CreateFile would raise an exception indicating that 'The filename, directory name, or volume label syntax is incorrect'. I found win32file.CreateFileW (documented to deal with 'unicode'), and that did return a handle for me. What puzzles me is that both functions take a PyUNICODE filename, so I just assumed that CreateFile would deal with the unicode pathname I was giving it. So, my question is, should I just use win32file.CreateFileW instead of win32file.CreateFile, and is it safe to use for all file handles, including those that do not have wide characters?
>
> Yes, win32file.CreateFileW will accept all file names: unicode strings are passed as is to the C function,
> and byte strings are properly converted to a wide string.
> But do you really need CreateFile? the plain open() function also accept unicode with Japanese characters...
I need to get the pyHANDLE to call win32file.DeviceIoControl (to set reparse data) and win32file.SetFileShortName, but if there's an easier way to programmatically set the 8.3 name on a file, please let me know.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120206/78f27cc9/attachment.html>
More information about the python-win32
mailing list