willsonlincake 发表于 2022-4-11 21:38:51

Python创建任何文件的快捷方式

import os, winshell, win32com.client, Pythoncom

desktop = winshell.desktop()
#desktop = r"path to where you wanna put your .lnk file"

path = os.path.join(desktop, 'File Shortcut Demo.lnk')
target = r"C:\Users\lenovo\Documents\sample2.txt"
icon = r"C:\Users\lenovo\Documents\sample2.txt"

shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.IconLocation = icon
shortcut.save()
页: [1]
查看完整版本: Python创建任何文件的快捷方式