E.g. the mingw python distributed in msys2 (the mingw one, which is a
normal win32 application and doesn't use the msys2 runtime itself),
despite being a normal win32 python, still uses forward slashes. This
works fine for other cases (many, but not all), but when constructing a
raw NT path, all path separators must be backslashes.
Differential Revision: https://reviews.llvm.org/D71490
from ctypes import GetLastError, WinError
path = os.path.abspath(path)
+ # Make sure that the path uses backslashes here, in case
+ # python would have happened to use forward slashes, as the
+ # NT path format only supports backslashes.
+ path = path.replace('/', '\\')
NTPath = to_unicode(r'\\?\%s' % path)
if not windll.kernel32.CreateDirectoryW(NTPath, None):
raise WinError(GetLastError())