我想在某些特定路径中创建某些文件的快捷方式(.lnk)。例如在(“ H:\ happy \ hi \ new.lnk”)中建立我的文件(“ D:\ New folder \ new.exe”)的快捷方式我想用python3编写此程序
pip install pywin32
pip install winshell
然后这是您必须编写的代码。
import os, winshell from win32com.client import Dispatch path = r"H:\happy\hi\new.lnk" // path to be saved (shortcut) target = r"D:\New folder\new.exe" // the shortcut target file or folder work_dir = r"D:\New folder" // the parent folder of your file shell = Dispatch('WScript.Shell') shortcut = shell.CreateShortCut(path) shortcut.Targetpath = target shortcut.WorkingDirectory = work_dir shortcut.save()
有关更多详细信息:https://winshell.readthedocs.io/en/latest/shortcuts.html