【发布时间】:2021-08-27 04:16:41
【问题描述】:
【问题讨论】:
标签: python python-3.x windows shortcut
【问题讨论】:
标签: python python-3.x windows shortcut
为此,您需要winshell,这将使查找特定于用户的路径和文件夹变得容易。这是脚本:
import os, winshell
desktop = winshell.desktop()
path = os.path.join(desktop, "ShortcutName.url")
target = "https://xxxxx.com"
shortcut = file(path, 'w')
shortcut.write('[InternetShortcut]\n')
shortcut.write('URL=%s' % target)
shortcut.close()
【讨论】:
with open('shortcut.url', mode='w', newline='\r\n') as f:
f.write("[InternetShortcut]\nURL=http://example.com")
选项 newline='\r\n' 确保您的脚本在 Mac 或 Linux 上运行时创建有效的 Windows 快捷方式。
【讨论】: