| | |
File size in C (Win32)
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2005
Posts: 188
Reputation:
Solved Threads: 3
Hi, I am trying to get the file size of a .exe file in C, I have tried using the GetFileSize(); function using the CreateFile(); function to get a handle for it, but the value returned is a DWORD and doesnt seem to work when i output it. I want to just retrieve the filesize of a .exe file and store this value in bytes in a long integer, does anyone have any other methods on this or can you help to correct my problem, here is my current code for this part:
Any suggestions ?
C Syntax (Toggle Plain Text)
HANDLE MF = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); DWORD Size; GetFileSize(MF,&Size); SendMessage(LogListBox,LB_ADDSTRING,0,(LPARAM)Size);
Look up
GetFileSize. C Syntax (Toggle Plain Text)
#include <stdio.h> #include <windows.h> int main(void) { const char FilePath[] = "main.exe"; HANDLE MF = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); if ( MF != INVALID_HANDLE_VALUE ) { DWORD High, Low = GetFileSize(MF, &High); if ( Low != 0xFFFFFFFF ) { printf("Size : High = %lu, Low = %lu\n", High, Low); } } return 0; } /* my output Size : High = 0, Low = 52736 */
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- file size (C++)
Other Threads in the C Forum
- Previous Thread: Hook Alert
- Next Thread: having a problem with this simple program am going crazy
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






