是否可以在python中的特定目录中创建快捷方式? [英] Is it possible to create shortcuts into a specific directory in python?
问题描述
我看着内网,但没有发现这一点,所以我问这里 -
是否可以创建一个文件的快捷方式,并把它放在我选择的特定目录与python?
例如,我在C:中有一个名为EXAMPLE的文件夹。我想自动创建Google Chrome的快捷方式并将其放在此文件夹中。是否可以使用python(而不只是自己拖动它)?
谢谢
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
推荐答案
我假设因为你提到C:你使用的是Windows。所以你可以使用winshell
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()
有关更多信息,请参阅 here
For more info look at here
如果您使用的是基于unix的系统,则可以使用符号链接命令。
If you're on a unix-based system you can use the symbolic link command.
这篇关于是否可以在python中的特定目录中创建快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!