Click here to Skip to main content
15,886,518 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: File size anf File size on disk PinPopular
Saurabh.Garg1-Oct-09 2:37
Saurabh.Garg1-Oct-09 2:37 
GeneralRe: File size anf File size on disk Pin
Member 41945931-Oct-09 8:21
Member 41945931-Oct-09 8:21 
GeneralRe: File size anf File size on disk Pin
Saurabh.Garg1-Oct-09 16:22
Saurabh.Garg1-Oct-09 16:22 
GeneralRe: File size anf File size on disk Pin
Iain Clarke, Warrior Programmer1-Oct-09 1:46
Iain Clarke, Warrior Programmer1-Oct-09 1:46 
AnswerRe: File size anf File size on disk Pin
peterchen1-Oct-09 0:14
peterchen1-Oct-09 0:14 
GeneralRe: File size anf File size on disk Pin
includeh101-Oct-09 0:22
includeh101-Oct-09 0:22 
GeneralRe: File size anf File size on disk Pin
peterchen1-Oct-09 5:26
peterchen1-Oct-09 5:26 
AnswerRe: File size and File size on disk Pin
Randor 1-Oct-09 2:29
professional Randor 1-Oct-09 2:29 
includeh10 wrote:
But which function gets "Size on disk"?


There are no standard API functions which return the storage allocation for a file on the disk. There are many variables which have an effect on file storage size. For standard non-compressed and non-sparse files you can calculate it something like this:

#include <sys\types.h>
#include <sys\stat.h>
__int64 GetFileSizeOnDisk(LPCTSTR szPath,LPCTSTR szDriveLetter)
{
	struct _stat64 st;
	DWORD dwClusterSize = 0;
	DWORD dwSectorsPerCluster = 0;
	DWORD dwBytesPerCluster =0;
	GetDiskFreeSpace(szDriveLetter,&dwSectorsPerCluster,&dwClusterSize,NULL,NULL);
	dwBytesPerCluster = dwClusterSize*dwSectorsPerCluster;
	int err = _tstat64(szPath, &st);
	return err != 0 ? LLONG_MIN : st.st_size+dwBytesPerCluster-st.st_size%dwBytesPerCluster;
}


Note that very tiny files on an NTFS partition which are less than 50% of 1 cluster have a high probability of being stored directly in the $MFT which makes the function above have no meaning. There may also be alternate file streams associated with the file which would technically also add to the total storage allocation. For a complete solution it should be possible to get all volume storage allocation by using the FSCTL_QUERY_ALLOCATED_RANGES[^] Control Code.

Best Wishes,
-David Delaune
QuestionTo construct a C++ code from a given Visual Basic String. Pin
Vishrant Shah30-Sep-09 22:56
Vishrant Shah30-Sep-09 22:56 
AnswerRe: To construct a C++ code from a given Visual Basic String. Pin
Hans Dietrich30-Sep-09 23:09
mentorHans Dietrich30-Sep-09 23:09 
AnswerRe: To construct a C++ code from a given Visual Basic String. Pin
Cedric Moonen30-Sep-09 23:12
Cedric Moonen30-Sep-09 23:12 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
Vishrant Shah30-Sep-09 23:59
Vishrant Shah30-Sep-09 23:59 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
Cedric Moonen1-Oct-09 0:07
Cedric Moonen1-Oct-09 0:07 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
Vishrant Shah1-Oct-09 0:14
Vishrant Shah1-Oct-09 0:14 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
Cedric Moonen1-Oct-09 0:18
Cedric Moonen1-Oct-09 0:18 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
Vishrant Shah1-Oct-09 0:41
Vishrant Shah1-Oct-09 0:41 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
Richard MacCutchan1-Oct-09 0:50
mveRichard MacCutchan1-Oct-09 0:50 
GeneralRe: To construct a C++ code from a given Visual Basic String. Pin
CPallini1-Oct-09 2:01
mveCPallini1-Oct-09 2:01 
AnswerRe: To construct a C++ code from a given Visual Basic String. Pin
CPallini30-Sep-09 23:20
mveCPallini30-Sep-09 23:20 
Questionvery strange memory problem ....please help Pin
dharani30-Sep-09 22:38
dharani30-Sep-09 22:38 
AnswerRe: very strange memory problem ....please help Pin
Hans Dietrich30-Sep-09 23:12
mentorHans Dietrich30-Sep-09 23:12 
AnswerRe: very strange memory problem ....please help Pin
KarstenK30-Sep-09 23:19
mveKarstenK30-Sep-09 23:19 
GeneralRe: very strange memory problem ....please help Pin
dharani30-Sep-09 23:39
dharani30-Sep-09 23:39 
GeneralRe: very strange memory problem ....please help Pin
KarstenK1-Oct-09 0:33
mveKarstenK1-Oct-09 0:33 
AnswerRe: very strange memory problem ....please help Pin
TimothyPMoore1-Oct-09 2:38
TimothyPMoore1-Oct-09 2:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.