[英]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:/Users
和C:/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.