python - 使用python3在Windows中创建文件的快捷方式(.lnk)
问题描述
我想在某些特定路径中创建某些文件的快捷方式(.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
推荐阅读
- python - 多个 pandas 组的条件求和,每个组由一组重叠的列值定义
- apostrophe-cms - srcset 的图像裁剪关系
- java - 如何在 Assertj 的帮助下检查该框架不包含带有特定文本的 jlabel?
- python-3.x - PyQt5 - 自定义 QWidget 未显示在父小部件上
- html - 使用 react-table 自定义分页
- c# - 不支持的媒体类型 415,但在 Postman 中工作正常
- python - Pandas 在 to_html() 之后将列与数字右对齐
- javascript - 迭代嵌套的 JSON 对象并将数据附加到变量
- elasticsearch - 在嵌套对象上处理 Stats 聚合中的缺失值
- docker - Swagger 页面有未捕获的异常烧瓶 restplus