I want to build a cross-platform application ,I used a windows API called 
SHOpenFolderAndSelectItems(). Although I found example called it by pywin32,but 
pywin32 is not available on Linux , I don't want to call a Windows API on 
linux,just don't want to make another code version for Linux,so I wonder how to 
access it by ctypes? yes,this API cannot be called on Linux ,I just want to 
make it silent in the code so that I can freeze the Python scripts into 
executables by cx_Freeze without pywin32 module-missing error happend .
from win32com.shell import shell, shellcon import os def 
launch_file_explorer(path, files):      '''      Given a absolute base path and 
names of its children (no path), open      up one File Explorer window with all 
the child files selected      '''      folder_pidl = 
shell.SHILCreateFromPath(path,0)[0]      desktop = shell.SHGetDesktopFolder()   
   shell_folder = desktop.BindToObject(folder_pidl, 
None,shell.IID_IShellFolder)      name_to_item_mapping = 
dict([(desktop.GetDisplayNameOf(item, 
shellcon.SHGDN_FORPARSING|shellcon.SHGDN_INFOLDER), item) for item in 
shell_folder])      print(name_to_item_mapping)      to_show = []      for file 
in files:          if file in name_to_item_mapping:              
to_show.append(name_to_item_mapping[file])          # else:              # 
raise Exception('File: "%s" not found in "%s"' % (file, path))      
shell.SHOpenFolderAndSelectItems(folder_pidl, to_show, 0) p=r'E:\aa' 
print(os.listdir(p)) launch_file_explorer(p, os.listdir(p))
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to