使用Python修改Windows unicode快捷方式
在这个问题之后,我决定使用以下Python代码来修改Windows快捷方式。
它适用于基于英语的快捷方式,但不适用于基于 unicode 的快捷方式。
如何修改此(或任何其他)代码片段以支持 unicode?
import re, os, pythoncom
from win32com.shell import shell, shellcon
shortcut_path = os.path.join(path_to_shortcut, shortcut_filename)
shortcut = pythoncom.CoCreateInstance (shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
persist_file.Load (shortcut_path)
destination1 = shortcut.GetPath(0)[0]
destination2 = os.path.join(destination_path, destination_filename)
shortcut.SetPath(destination2)
persist_file.Save(shortcut_path, 0)
假设以下内容是 unicode:path_to_shortcut
、shortcut_filename
、destination_path
、destination_filename
Following this question, I've settled on the following Python code to modify Windows shortcuts.
It works for English based shortcuts but it doesn't for unicode based shortcuts.
How could this (or any other) snippet be modified to support unicode?
import re, os, pythoncom
from win32com.shell import shell, shellcon
shortcut_path = os.path.join(path_to_shortcut, shortcut_filename)
shortcut = pythoncom.CoCreateInstance (shell.CLSID_ShellLink, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
persist_file.Load (shortcut_path)
destination1 = shortcut.GetPath(0)[0]
destination2 = os.path.join(destination_path, destination_filename)
shortcut.SetPath(destination2)
persist_file.Save(shortcut_path, 0)
Assume the following are unicode: path_to_shortcut
, shortcut_filename
, destination_path
, destination_filename
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许看这里可能会有所帮助: Python Unicode HOWTO
我猜你需要确保每个字符串都正确编码为 Unicode,并且任何更改都需要保留该编码。该文章应该提供您需要的所有信息。
Perhaps looking here may help: Python Unicode HOWTO
I'm guessing you'd need to be sure that each of those strings was properly encoded as Unicode and any changes need to preserve that encoding. That article should provide all the information you'll need.
我知道编辑 unicode 快捷方式的两种方法,
winshell
和pylnk3
。我会推荐
winshell
因为pylnk3
有一些错误。winshell
pylnk3
I know 2 ways to edit unicode shortcuts,
winshell
andpylnk3
.I would recommend
winshell
becausepylnk3
has some bug.winshell
pylnk3