import os

# filename=r"u:\D1\Days\Stefajir\core\misc\draggable.png"
filename=r"u:\1.png"

import ctypes
from ctypes import wintypes


def getfilesize(file_path):
    # Get compressed size (if file is compressed)
    file_size_high = wintypes.DWORD()
    file_size_real = ctypes.windll.kernel32.GetFileSizeEx(
        file_path,
        ctypes.byref(file_size_high),
    )
    return file_size_real


def get_real_file_size_win(file_path):
    # Get cluster size (allocation unit) from the filesystem
    drive = os.path.splitdrive(file_path)[0] + "\\"
    sectors_per_cluster = wintypes.DWORD()
    bytes_per_sector = wintypes.DWORD()
    ctypes.windll.kernel32.GetDiskFreeSpaceW(
        drive,
        ctypes.byref(sectors_per_cluster),
        ctypes.byref(bytes_per_sector),
        None,
        None,
    )
    cluster_size = sectors_per_cluster.value * bytes_per_sector.value

    # Get compressed size (if file is compressed)
    file_size_high = wintypes.DWORD()
    file_size_low = ctypes.windll.kernel32.GetCompressedFileSizeW(
        file_path,
        ctypes.byref(file_size_high),
    )
    # compressed_size = (file_size_high.value << 32) + file_size_low #.value
    #
    # # If not compressed, fall back to cluster-based allocation
    # if compressed_size == 0:
    #     file_size = os.path.getsize(file_path)
    #     real_size = ((file_size + cluster_size - 1) // cluster_size) * cluster_size
    # else:
    #     real_size = compressed_size

    return file_size_low

# print(get_real_file_size_win(filename))
print(getfilesize(filename))



# cesta=r"u:\d1"
#
# for root, dirs, files in os.walk(cesta):
#     for file in files:
#         soubor=os.path.join(root,file)
#         print(soubor)
#         realsize=get_real_file_size_win(soubor)
#         print(realsize)
#         # print(soubor,f"Real size on disk (Windows): {realsize} bytes")
#         if realsize==0 or file[0]=="~" or file.upper()=="THUMBS.DB" or file.upper()=="DESCR.WD3":
#             print(f"Deleting file {soubor}")
#             os.remove(soubor)
#
