2011-08-02 7 views
1

this questionに続いて、私はWindowsのショートカットを変更するために次のPythonコードを解決しました。
英語ベースのショートカットでは機能しますが、ユニコードベースのショートカットでは機能しません。Pythonを使用してWindowsユニコードショートカットを変更する

この(または他の)スニペットをにユニコードに対応させるにはどうすればよいですか?

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) 

次ユニコードされていると仮定しますpath_to_shortcutshortcut_filenamedestination_pathdestination_filename

+0

ユニコードショートカットではどうなりますか? – agf

+0

この問題は、ショートカットを扱おうとしたとき、または 'shell'クラスを使用しているときにのみ起こりますか?おそらく、Windowsのショートカットだけでなく、一般的にUnicodeを使用するように質問を拡張する必要がありますか? – Hnatt

答えて

0

はおそらくここに見ると役立つことがあります。Python Unicode HOWTO

私はあなたがそれらのそれぞれのことを確認する必要があるだろう推測しています文字列はUnicodeとして適切にエンコードされており、変更によってそのエンコードが保持される必要があります。この記事では、必要なすべての情報を提供する必要があります。

関連する問題