我想通过python创建一个快捷方式,它将在另一个带有参数的程序中启动一个文件。例如:Python,创建两个路径和参数的快捷方式
"C:\file.exe" "C:\folder\file.ext" argument
我已经试过搞乱代码:
from win32com.client import Dispatch
import os
shell = Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = r'"C:\file.exe" "C:\folder\file.ext"'
shortcut.Arguments = argument
shortcut.WorkingDirectory = "C:\" #or "C:\folder\file.ext" in this case?
shortcut.save()
,但我得到一个错误时,抛出我的方式:
AttributeError: Property '<unknown>.Targetpath' can not be set.
我试过字符串的不同格式谷歌似乎并不知道这个问题的解决方案
谢谢,这工作! :)但我不得不做一个快速而脏的'path ='“%s”'%path',以确保第二个路径在字符串周围有引号。您在TargetPath中放置的路径会自动根据需要添加引号(空格在路径中) – coco4l
很高兴听到它适合您!如果您对解决方案感到满意,您可以接受答案。 :) – wombatonfire