Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

What size is this folder?

4.00/5 (1 vote)
12 May 2010CPOL 8.4K  
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!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)