News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Retrieving the size of a file

Started by Vortex, Yesterday at 09:17:14 PM

Previous topic - Next topic

Vortex

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
Code it... That's all...

TimoVJL

#1
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.
May the source be with you

Vortex

#2
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;
Code it... That's all...