Pelles C forum

Assembly language => Assembly discussions => Topic started by: Vortex on November 08, 2026, 09:17:14 PM

Title: Retrieving the size of a file
Post by: Vortex on November 08, 2026, 09:17:14 PM
Enhanced version of the filesize function from the Masm32 library :
.386
.model flat,stdcall
option casemap:none

include filesize.inc

.code

filesize PROC lpszFileName:DWORD

LOCAL wfd:WIN32_FIND_DATA

    invoke  FindFirstFile,lpszFileName,ADDR wfd
    cmp     eax,INVALID_HANDLE_VALUE
    jz      fsEnd 

    invoke  FindClose,eax

    mov     eax,wfd.nFileSizeLow

fsEnd:

    ret

filesize ENDP

END
Title: Re: Retrieving the size of a file
Post by: TimoVJL on November 08, 2026, 10:10:39 PM
GetFileAttributesEx is simpler, but have an own features.

EDIT: function name fixed.

Also using FindFirstFileEx with FindExInfoBasic, if short name isn't needed.
A FindFirstFile is just a wrap function to FindFirstFileEx.

GetFileAttributesEx fails with "C:/pagefile.sys" with sharing error,
FindFirstFile not.
Title: Re: Retrieving the size of a file
Post by: Vortex on November 08, 2026, 10:16:46 PM
Hi Timo,

Thanks. Here is WIN32_FILE_ATTRIBUTE_DATA structure :

typedef struct _WIN32_FILE_ATTRIBUTE_DATA {
  DWORD    dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD    nFileSizeHigh;
  DWORD    nFileSizeLow;
} WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;