Is it possible to create shortcuts into a specific directory in python?

ε祈祈猫儿з 提交于 2019-12-20 02:11:14

问题


I looked over the inetrnet but found nothing about this so I ask here - Is it possible to create a shortcut of a file and put it in a specific directory of my choose with python? For example, I have a folder named "EXAMPLE" in ' C: ' . I want to create automatically a shortcut of Google Chrome and put it in this folder. Is it possible to do so using python(and not just dragging it over by myself)? Thanks


回答1:


I assume because of you mention C: that you're using windows. So you can use winshell

import os, winshell
from win32com.client import Dispatch

desktop = winshell.desktop()
path = os.path.join(desktop, "Media Player Classic.lnk")
target = r"P:\Media\Media Player Classic\mplayerc.exe"
wDir = r"P:\Media\Media Player Classic"
icon = r"P:\Media\Media Player Classic\mplayerc.exe"

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()

For more info look at here

If you're on a unix-based system you can use the symbolic link command.



来源:https://stackoverflow.com/questions/32154767/is-it-possible-to-create-shortcuts-into-a-specific-directory-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!