Silviu-Marius Ardelean's blog

a software engineer's web log

File size fast detection

Many times in our job, we need to work with files and need to know file properties.
One of the most important properties is file size. Of course, there are a lot of API that allows finding this property, but most of them needs additional file operations: open file, find file size and close file.

A direct and fast way in order to detect the file size without these operations means the CRT run-time library’s function _tstat64() and stuff.

In the header file or on .cpp file please add next macros definitions:

Then, write next function:

If you’re using WinAPI there is an even faster way in order to get file size.

Finally, call these functions wherever you need.

Share