简体   繁体   English

在python中的Windows中创建Web快捷方式

[英]Create web shortcut in windows in python

Create shortcut files in Windows 10 using Python 3.7.1 使用 Python 3.7.1 在 Windows 10 中创建快捷方式文件

this is for shortcut to local files这是本地文件的快捷方式

How to create a shortcut to https://xxxxx.com如何创建到https://xxxxx.com的快捷方式

You'll be needing winshell for this, which would make finding user-specific paths and folders easy.为此,您将需要winshell ,这将使查找特定于用户的路径和文件夹变得容易。 Here's the script:这是脚本:

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")

Option newline='\r\n' is required to make sure your script will create valid Windows shortcut while running on Mac or Linux.需要选项newline='\r\n'以确保您的脚本在 Mac 或 Linux 上运行时将创建有效的 Windows 快捷方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM