Tags
dev c++
Asked 8 years ago
17 Aug 2016
Views 1149
david

david posted

Needed function to grab size of the file at dev c++

Hi

i am making for window based application and i want a function where i can pass filename as argument and get back the filesize as return .

yes you are thinking right i am beginner at dev c++ development at win32 api

dilip

dilip
answered Nov 30 '-1 00:00

why dont you use GetFileSize function like as below


	filesize = GetFileSize(file, NULL);



here file is handle of the file . use CreateFile function to get handle of the file

so final code like this


	file = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
	DWORD filesize;
       
       filesize = GetFileSize(file, NULL);
       if(filesize != 0xFFFFFFFF) {
       // do read or write of the file because you file is not empty 
       }

Post Answer