Modify Windows unicode shortcuts using Python

落爺英雄遲暮 提交于 2019-12-02 15:40:30

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6916069/modify-windows-unicode-shortcuts-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!