Whats the most efficient way to check if a file is empty? Thanks for any input!
GetFileSize()
GetFileAttributesEx
xor eax,eax
push eax
push eax
sub esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-8
INVOKE GetFileAttributesEx,offset szFileName,eax,esp
add esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-8
pop edx ;EDX = file size high dword
pop eax ;EAX = file size low dword
or eax,edx
jnz file_is_not_empty
file_is_empty_or_is_not_a_file_or_does_not_exist:
i hate guys that use really long labels :P
include \masm32\MasmBasic\MasmBasic.inc ; download (http://www.masm32.com/board/index.php?topic=12460)
Init
Open "O", #1, "Empty.txt"
Close #1
Print Str$("no such file:\t%i\n", Lof("BadFile.txt"))
Print Str$("empty file:\t%i\n", Lof("Empty.txt"))
Inkey Str$("regular file:\t%i\n", Lof("\Masm32\include\Windows.inc"))
Exit
end start
no such file: -1
empty file: 0
regular file: 977412
:wink
another option...
xor eax,eax
push eax
push eax
sub esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-12
push eax
INVOKE GetFileAttributesEx,offset szFileName,eax,esp
pop ecx ;ECX = file attributes
add esp,sizeof WIN32_FILE_ATTRIBUTE_DATA-12
pop edx ;EDX = file size high dword
pop eax ;EAX = file size low dword
if the function fails (which indicates the object does not exist), EAX, ECX, and EDX will all be 0
if the object exists, whether it be a file, folder, or device, ECX will be non-zero