Windows 上的符号链接? [英] Symlinks on windows?

查看:53
本文介绍了Windows 上的符号链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道从 Python 跨版本的 win32 创建/读取符号链接的方法?理想情况下应该有最少数量的平台特定代码,因为我需要我的应用跨平台.

Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform.

推荐答案

NTFS 文件系统有连接点,我想你可以用它们代替,你可以使用 python win32 API 模块,例如

NTFS file system has junction points, I think you may use them instead, You can use python win32 API module for that e.g.

import win32file

win32file.CreateSymbolicLink(fileSrc, fileTarget, 1)

如果不想依赖win32API模块,可以随时使用ctypes,直接调用CreateSymbolicLink win32 API e.g.

If you do not want to rely on win32API module, you can always use ctypes and directly call CreateSymbolicLink win32 API e.g.

import ctypes

kdll = ctypes.windll.LoadLibrary("kernel32.dll")

kdll.CreateSymbolicLinkA("d:\\test.txt", "d:\\test_link.txt", 0)

MSDN (http://msdn.microsoft.com/en-us/library/aa363866(VS.85).aspx) 说最低支持的客户端是 Windows Vista

MSDN (http://msdn.microsoft.com/en-us/library/aa363866(VS.85).aspx) says Minimum supported client is Windows Vista

另外:这也适用于目录(用第三个参数表示).有了 unicode 支持,它看起来像这样:

In addition: This also works with directories (indicate that with the third argument). With unicode support it looks like this:

kdll.CreateSymbolicLinkW(UR"D:\testdirLink", UR"D:\testdir", 1)

另见在 Python 中创建 NTFS 连接点

这篇关于Windows 上的符号链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆