vinzon
vinzon

Reputation: 148

Open and Select Item in Windows Explorer (Unicode) - Python

I know how to open and select file in windows explorer by using explorer.exe commandline options '/n,@/select ' but I can only make it work with regular characters. Anyone have idea how to make it support unicode characters such as this 五輪代? I've tried to encode it with 'utf-8' but it didn't work, I'm sure there's a proper way to do it I just don't know how I hope someone can give me idea. Thanks in advance! :)

here's my sample code:

import win32api

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

Upvotes: 0

Views: 1715

Answers (2)

Janne Karila
Janne Karila

Reputation: 25207

You can use ctypes to access the API in a more direct way: (file_path should be a Python unicode object, not utf-8)

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

Upvotes: 4

ApprenticeHacker
ApprenticeHacker

Reputation: 22031

this may be of some use. It's for using unicode filenames with python. But it doesn't mention anything about pyWin32.

Upvotes: 0

Related Questions