Ere*_*ons 3 python directory shortcut
我查看了 inetrnet,但没有发现任何相关内容,所以我在这里问 - 是否可以使用 python 创建文件的快捷方式并将其放入我选择的特定目录中?例如,我在“C:”中有一个名为“EXAMPLE”的文件夹。我想自动创建谷歌浏览器的快捷方式并将其放在这个文件夹中。是否可以使用 python 来做到这一点(而不仅仅是我自己拖过去)?谢谢
我假设因为你提到了 C: 你正在使用 Windows。这样就可以使用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()
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息,请看这里
如果您使用的是基于 UNIX 的系统,则可以使用符号链接命令。