在Windows资源管理器中打开并选择项目(Unicode) - Python

0 投票
2 回答
1711 浏览
提问于 2025-04-17 08:16

我知道怎么通过使用 explorer.exe 的命令行选项 '/n,@/select ' 来打开和选择 Windows 资源管理器中的文件,但我只能用普通字符来实现。有没有人知道怎么让它支持像五輪代这样的 Unicode 字符?我试过用 'utf-8' 编码,但没有成功。我相信有正确的方法,只是我不知道怎么做,希望有人能给我点建议。提前谢谢你们!:)

这是我的示例代码:

import win32api

win32api.ShellExecute(None, 'open', 'explorer.exe',
                      '/n,@/select, ' + file_path, None, 1)

2 个回答

0

这个链接可能对你有帮助。它讲的是如何在Python中使用Unicode文件名。不过里面没有提到pyWin32的相关内容。

4

你可以使用 ctypes 来更直接地访问API:(file_path应该是一个Python的unicode对象,而不是utf-8格式)

import ctypes
ctypes.windll.shell32.ShellExecuteW(None, u'open', u'explorer.exe', 
                                    u'/n,/select, ' + file_path, None, 1)

撰写回答