65.9K
CodeProject is changing. Read more.
Home

What size is this folder?

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

May 12, 2010

CPOL
viewsIcon

8437

An alternative to iterating a folder's contents to get the size is to use the scripting object, FileSystemObject.Using ClassWizard (Ctrl+W), the first thing you'll need to do is add the classes contained in the Script Runtime engine (scrrun.dll). This will add scrrun.cpp and scrrun.h to...

An alternative to iterating a folder's contents to get the size is to use the scripting object, FileSystemObject. Using ClassWizard (Ctrl+W), the first thing you'll need to do is add the classes contained in the Script Runtime engine (scrrun.dll). This will add scrrun.cpp and scrrun.h to your project. As its not needed, you'll likely need to comment out the IDrive class and its methods. Now we just have to create the object and call its GetSize() method, like:
CoInitialize(NULL);

IFileSystem fso;
if (fso.CreateDispatch(_T("Scripting.FileSystemObject")) == TRUE)
{
    IFolder folder;
    folder = fso.GetFolder(_T("C:\\Windows\\System32"));
            
    _variant_t vtSize = folder.GetSize();
}
Enjoy!