【问题标题】:Is it possible to create shortcuts into a specific directory in python?是否可以在 python 中创建特定目录的快捷方式?
【发布时间】:2015-08-22 09:57:31
【问题描述】:

我查看了 inetrnet,但没有发现任何相关信息,所以我在这里问 - 是否可以创建文件的快捷方式并将其放在我使用 python 选择的特定目录中? 例如,我在 'C:' 中有一个名为“EXAMPLE”的文件夹。我想自动创建一个谷歌浏览器的快捷方式并将它放在这个文件夹中。是否可以使用 python 来做到这一点(而不仅仅是自己拖过来)? 谢谢

【问题讨论】:

  • 你用的是哪个操作系统?

标签: python directory shortcuts


【解决方案1】:

我假设因为您提到 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()

更多信息请查看here

如果您使用的是基于 unix 的系统,则可以使用符号链接命令。

【讨论】:

  • 谢谢!另外,是否可以在创建新快捷方式之前检查快捷方式是否已经存在?这样同一个文件只有1个快捷方式,不超过1个..?
  • 这只是一个文件,所以你可以这样做:stackoverflow.com/questions/82831/…
猜你喜欢
  • 2015-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多