Files
projects/TestFileSizeZero2.py
michaela.buzalkova b45a8b2d00 Initial commit
2025-09-30 08:22:44 +02:00

41 lines
1.3 KiB
Python

import os
import ctypes as ct
import ctypes.wintypes as w
NO_ERROR = 0
INVALID_FILE_SIZE = w.DWORD(0xFFFFFFFF).value
INVALID_FILE_ATTRIBUTES = w.DWORD(-1).value
FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000
# Helpers to raise exceptions on API failures.
def filesizecheck(result, func, args):
if result == INVALID_FILE_SIZE and (err := ct.get_last_error()) != NO_ERROR:
raise ct.WinError(err)
return result
def attributecheck(result, func, args):
if result == INVALID_FILE_ATTRIBUTES:
raise ct.WinError(ct.get_last_error())
return result
kernel32 = ct.WinDLL('kernel32', use_last_error=True)
GetCompressedFileSize = kernel32.GetCompressedFileSizeW
GetCompressedFileSize.argtypes = w.LPCWSTR, w.LPDWORD
GetCompressedFileSize.restype = w.DWORD
GetCompressedFileSize.errcheck = filesizecheck
GetFileAttributes = kernel32.GetFileAttributesW
GetFileAttributes.argtypes = w.LPCWSTR,
GetFileAttributes.restype = w.DWORD
GetFileAttributes.errcheck = attributecheck
fullpath=r"u:\D1\Days\Stefajir\user\default.htm"
local_size = GetCompressedFileSize(fullpath, None)
attributes = GetFileAttributes(fullpath)
print(local_size)
print(attributes)
print(FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS)
if attributes & FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS and local_size != 0:
print(f'0x{attributes:08X} {local_size:6d} {fullpath}')