trying to get the size of a file
-
Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.
-
Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.
The first arguments should be: const char *path - the routine shouldn't be modifying the text. const CString &path - Same thing again but also avoids an extra copy constructor. const std::string &path - Same thing as with const CString &path. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.
Off the top of my head.
// Open file for reading
if ((hFile = CreateFile (filePath, GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE)NULL)) == (HANDLE)(-1))
{
return 0;
}DWORD dwFileSize = GetFileSize (hFile, NULL); // Get the size of the file.
return dwFileSize;
Michael But you know when the truth is told, That you can get what you want or you can just get old, Your're going to kick off before you even get halfway through. When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
-
Hi! I just need to get the size of a file. The file is given by path (i.e: 'c:\thefile.txt'). I've been dealing with this for days, but I always bump into troubles. May I ask someone to write me a very simple function, which queries the size of a file. That would show me how to get the size, and then I'd know what am I doing wrong. @win32/vc++ 6.0 Thx in forward.
There are various ways, but you probably want one of the following: GetFileSize() GetFileSizeEx() (For sizes larger than a DWORD value) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
There are various ways, but you probably want one of the following: GetFileSize() GetFileSizeEx() (For sizes larger than a DWORD value) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
thank you both for the help, anyway I've managed to figure it out myself, however due to a netsplit I couldn't access codeproject.com, I made a func almost similar you described. btw. it's possible to get the size of a file with GetFileSize, as if it puts the high dword to the DWORD pointed by the second argument.