簡體   English   中英

使用python3在windows中創建文件的快捷方式(.lnk)

[英]create a shortcut(.lnk) of file in windows with python3

我想在某些特定路徑中創建某些文件的快捷方式(.lnk)。 例如在 ("H:\\happy\\hi\\new.lnk") 中創建我的文件的快捷方式("D:\\New folder\\new.exe") 我想在 python3 中編寫這個程序

一、安裝需求

pip install pywin32
pip install winshell

那么這就是您必須編寫的代碼。

import os, winshell
from win32com.client import Dispatch

path = r"H:\happy\hi\new.lnk"  # Path to be saved (shortcut)
target = r"D:\New folder\new.exe"  # The shortcut target file or folder
work_dir = r"D:\New folder"  # The parent folder of your file

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

更多詳情: https : //winshell.readthedocs.io/en/latest/shortcuts.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM