def symlink_ms(source, linkname):
"""Python 2 doesn't have os.symlink on windows so we do it ourselfs
:param source: sourceFile
:type source: str
:param linkname: symlink path
:type linkname: str
:raises: WindowsError, raises when it fails to create the symlink if the user permissions
are incorrect
"""
import ctypes
csl = ctypes.windll.kernel32.CreateSymbolicLinkW
csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
csl.restype = ctypes.c_ubyte
flags = 1 if os.path.isdir(source) else 0
try:
if csl(linkname, source.replace('/', '\\'), flags) == 0:
raise ctypes.WinError()
except WindowsError:
raise WindowsError("Failed to create symbolicLink due to user permissions")
评论列表
文章目录