使用 Python 修改 Windows unicode 快捷方式 [英] Modify Windows unicode shortcuts using Python

查看:50
本文介绍了使用 Python 修改 Windows unicode 快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题之后,我确定了以下Python代码进行修改Windows 快捷方式.
它适用于基于英语的快捷方式,但不适用于基于 Unicode 的快捷方式.

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.

如何修改此(或任何其他)代码段以支持 unicode?

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)

假设以下是unicode:path_to_shortcutshortcut_filenamedestination_pathdestination_filename

Assume the following are unicode: path_to_shortcut, shortcut_filename, destination_path, destination_filename

推荐答案

也许看这里可能会有所帮助:Python Unicode HOWTO

Perhaps looking here may help: Python Unicode HOWTO

我猜您需要确保这些字符串中的每一个都正确编码为 Unicode,并且任何更改都需要保留该编码.那篇文章应该会提供您需要的所有信息.

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.

这篇关于使用 Python 修改 Windows unicode 快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆