Create NTFS junction point in Python

后端 未结 5 1323
一整个雨季
一整个雨季 2020-12-05 11:02

Is there a way to create an NTFS junction point in Python? I know I can call the junction utility, but it would be better not to rely on external tools.

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 11:40

    you can use python win32 API modules e.g.

    import win32file
    
    win32file.CreateSymbolicLink(srcDir, targetDir, 1)
    

    see http://docs.activestate.com/activepython/2.5/pywin32/win32file__CreateSymbolicLink_meth.html for more details

    if you do not want to rely on that too, you can always use ctypes and directly call CreateSymbolicLinl win32 API, which is anyway a simple call

    here is example call using ctypes

    import ctypes
    
    kdll = ctypes.windll.LoadLibrary("kernel32.dll")
    
    kdll.CreateSymbolicLinkA("d:\testdir", "d:\testdir_link", 1)
    

    MSDN says Minimum supported client Windows Vista

提交回复
热议问题