--lua
local ffi = require("ffi")
local GENERIC_READ = 0x80000000
local OPEN_EXISTING = 3
local INVALID_HANDLE_VALUE = -1
ffi.cdef[[ unsigned long GetFileSize(int hFile, unsigned long* lpFileSizeHigh);
int CreateFileA(const char* lpFileName, unsigned long dwDesiredAccess, unsigned long dwShareMode, int lpSecurityAttributes,
unsigned long dwCreationDisposition, unsigned long dwFlagsAndAttributes, int hTemplateFile);
bool CloseHandle(int hObject);
]]
function get_file_size(file_name)
local hFile = ffi.C.CreateFileA(file_name, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)
if hFile == INVALID_HANDLE_VALUE then
log('Файл не открылся')
return nil
end
local size_file = ffi.C.GetFileSize(hFile, nil)
ffi.C.CloseHandle(hFile)
return size_file
end
local result = get_file_size([[C:\Windows\notepad.exe]]) -- размер файла
log (result)