Introduction
XFolderSize is small class to get folder size information
based on starting folder. You use XFolderSize like this:
LARGE_INTEGER li;
DWORD dwFolderCount = 0;
DWORD dwFileCount = 0;
CXFolderSize fs;
BOOL rc = fs.GetFolderSize(_T("C:\\myfolder"), TRUE, TRUE, &li,
&dwFolderCount, &dwFileCount);
The GetFolderSize()
function allows you to specify whether to
recurse into subdirectories, whether to treat root directory of drive
in special way (using SHGetDiskFreeSpace()
to get
total size), and optionally will return folder count and file count.
Because file sizes may be over 4 Gb, the LARGE_INTEGER
type is used. This is what is returned by Win32 API
GetFileSizeEx()
:
BOOL GetFileSizeEx(HANDLE hFile,
PLARGE_INTEGER lpFileSize);
XFolderSize may be used only in Windows 2000 and later,
since GetFileSizeEx()
is not available in earlier
versions of Windows.
Implementation Details
XFolderSize offers two functions:
- GetFolderSize():
BOOL CXFolderSize::GetFolderSize(LPCTSTR lpszStartFolder,
BOOL bRecurse,
BOOL bQuickSize,
PLARGE_INTEGER lpFolderSize,
LPDWORD lpFolderCount ,
LPDWORD lpFileCount )
- GetFileSize64():
BOOL CXFolderSize::GetFileSize64(LPCTSTR lpszPath, PLARGE_INTEGER lpFileSize)
Demo App
The demo app allows you to try out XFolderSize on your own system:
You can also use Quick Size option to get the size used by
an entire drive:
How To Use
To integrate CXFolderSize
class into your app, do the following:
- You first need to add following files to your project:
- XFolderSize.cpp
- XFolderSize.h
- In Visual Studio settings, select
Not using pre-compiled header for XFolderSize.cpp.
- Next, include header file
XFolderSize.h in source file where you want to use
CXFolderSize
.
- Now you are ready to start using
CXFolderSize
. Your code should look something like:
LARGE_INTEGER li;
DWORD dwFolderCount = 0;
DWORD dwFileCount = 0;
CXFolderSize fs;
BOOL rc = fs.GetFolderSize(_T("C:\\myfolder"), TRUE, TRUE, &li,
&dwFolderCount, &dwFileCount);
Revision History
Version 1.0 — 2007 June 11
Usage
This software is released into the public domain. You are free to
use it in any way you like, except that you may not sell this source code.
If you modify it or extend it, please to consider posting new code here
for everyone to share. This software is provided "as is" with no
expressed or implied warranty. I accept no liability for any damage or
loss of business that this software may cause.