使用python3在Windows中创建文件的快捷方式(.lnk)

问题描述 投票:1回答:1

我想在某些特定路径中创建某些文件的快捷方式(.lnk)。例如在(“ H:\ happy \ hi \ new.lnk”)中建立我的文件(“ D:\ New folder \ new.exe”)的快捷方式我想用python3编写此程序

python python-3.x windows shortcut lnk
1个回答
0
投票
首先,安装要求

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
© www.soinside.com 2019 - 2024. All rights reserved.