Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / C++
Tip/Trick

What size is this folder?

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
12 May 2010CPOL 8.2K   1   1
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)


Written By
Software Developer (Senior) Pinnacle Business Systems
United States United States

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

HTTP 404 - File not found
Internet Information Services

Comments and Discussions

 
GeneralHI,friend DavidCrow, what's IDriver class? Pin
upsonn13-May-10 21:54
upsonn13-May-10 21:54 

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.