简体   繁体   中英

Create web shortcut in windows in python

Create shortcut files in Windows 10 using Python 3.7.1

this is for shortcut to local files

How to create a shortcut to https://xxxxx.com

You'll be needing winshell for this, which would make finding user-specific paths and folders easy. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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