python模仿windows文件管理_python – 在Windows中显示文件的资源管理器属性对话框...
這樣做的方法是調用Windows
ShellExecuteEx() API傳遞屬性動詞.有各種高級Python包裝器,但我沒有成功地使用屬性動詞.相反,我會使用好老的ctypes.
import time
import ctypes
import ctypes.wintypes
SEE_MASK_NOCLOSEPROCESS = 0x00000040
SEE_MASK_INVOKEIDLIST = 0x0000000C
class SHELLEXECUTEINFO(ctypes.Structure):
_fields_ = (
("cbSize",ctypes.wintypes.DWORD),
("fMask",ctypes.c_ulong),
("hwnd",ctypes.wintypes.HANDLE),
("lpVerb",ctypes.c_char_p),
("lpFile",ctypes.c_char_p),
("lpParameters",ctypes.c_char_p),
("lpDirectory",ctypes.c_char_p),
("nShow",ctypes.c_int),
("hInstApp",ctypes.wintypes.HINSTANCE),
("lpIDList",ctypes.c_void_p),
("lpClass",ctypes.c_char_p),
("hKeyClass",ctypes.wintypes.HKEY),
("dwHotKey",ctypes.wintypes.DWORD),
("hIconOrMonitor",ctypes.wintypes.HANDLE),
("hProcess",ctypes.wintypes.HANDLE),
)
ShellExecuteEx = ctypes.windll.shell32.ShellExecuteEx
ShellExecuteEx.restype = ctypes.wintypes.BOOL
sei = SHELLEXECUTEINFO()
sei.cbSize = ctypes.sizeof(sei)
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_INVOKEIDLIST
sei.lpVerb = "properties"
sei.lpFile = "C:\\Desktop\\test.txt"
sei.nShow = 1
ShellExecuteEx(ctypes.byref(sei))
time.sleep(5)
我調用sleep的原因是屬性對話框在調用進程中顯示為一個窗口.如果Python可執行文件在調用ShellExecuteEx之后立即終止,則沒有任何內容可以為對話框提供服務而且它不會顯示.
總結
以上是生活随笔為你收集整理的python模仿windows文件管理_python – 在Windows中显示文件的资源管理器属性对话框...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 特殊函数_MySQL中sle
- 下一篇: python一球从100米高度自由落下,