If you are using Python 2.5 or later on Windows, you can also use the Windows API without pywin32 using ctypes.
from ctypes import windll, POINTER from ctypes.wintypes import LPWSTR, DWORD, BOOL SCS_32BIT_BINARY = 0 # A 32-bit Windows-based application SCS_64BIT_BINARY = 6 # A 64-bit Windows-based application SCS_DOS_BINARY = 1 # An MS-DOS-based application SCS_OS216_BINARY = 5 # A 16-bit OS/2-based application SCS_PIF_BINARY = 3 # A PIF file that executes an MS-DOS-based application SCS_POSIX_BINARY = 4 # A POSIX-based application SCS_WOW_BINARY = 2 # A 16-bit Windows-based application _GetBinaryType = windll.kernel32.GetBinaryTypeW _GetBinaryType.argtypes = (LPWSTR, POINTER(DWORD)) _GetBinaryType.restype = BOOL def GetBinaryType(filepath): res = DWORD() handle_nonzero_success(_GetBinaryType(filepath, res)) return res
Then use GetBinaryType in the same way as with win32file.GetBinaryType.
Please note: you will need to implement handle_nonzero_success, which basically throws an exception if the return value is 0.
Jason R. coombs
source share