Possible Duplicate:
How do you get the file size in C#?
How can I calculate the size of any file in C++ or Visual C++/.NET or C#?
I mean a .exe, .txt, .doc, etc. file.
Possible Duplicate:
How do you get the file size in C#?
How can I calculate the size of any file in C++ or Visual C++/.NET or C#?
I mean a .exe, .txt, .doc, etc. file.
What do you mean "calculate"?
You just ask the file system, "how big is that file?", and it gives you the length, no calculation involved.
What is your question exactly?
How to do that in C#?
Here's code that will give you the length of a file, there are other ways as well:
long length = new FileInfo(@"c:\temp\test.exe").Length;
You can do it in C++ this way:
Taken directly from cplusplus.com
// Obtaining file size
#include <iostream>
#include <fstream>
using namespace std;
int main () {
long begin,end;
ifstream myfile ("example.txt");
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();
cout << "size is: " << (end-begin) << " bytes.\n";
return 0;
}
If you just want the size of the File, you can do this in C#:
long size = new System.IO.FileInfo("<path to file>").Length;
Another variant that matches your request -- Visual C++ using Windows File Management API:
LARGE_INTEGER liFileSize;
HANDLE hFile;
// open/create file
GetFileSizeEx(hFile, &liFileSize);
// close handle
Use stat.
struct stat buf;
fstat(fd, &buf);
int size = buf.st_size;