繁体   English   中英

如何创建指向 python 中文件夹的 windows 快捷方式

[英]how to create a windows shortcut to a folder in python

我的问题是我找不到创建文件夹快捷方式的解决方案 python。仅针对文件,代码示例:

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.save()

但我需要整个文件夹的快捷方式。

我的目标示例是:

C:/UsersC:/Users/user/Downloads

您可以使用以下代码创建目录的快捷方式

from win32com.client import Dispatch

path = r"C:\Users\user\Downloads\shortcut.lnk"  #This is where the shortcut will be created
target = r"C:\Users\user\Downloads" # directory to which the shortcut is created

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.save()

必须在shortcut.Targetpath方式中使用反斜杠( \ )。快捷方式的目标路径才能在文件夹中正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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