filesystem.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:zoocore 作者: dsparrow27 项目源码 文件源码
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")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号