Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Folder utilities

0.00/5 (No votes)
31 Jan 2005 1  
Folder utilities such as creating, removing, copying folders and getting folder's space.

Introduction

The CreateDirectory WIN32 API lets us create a folder. However, this function will succeed only if the parent folder exists. For example, creating a folder C:\AA\BB\CC\DD succeeds only if the parent folder C:\AA\BB\CC exists. Thus, CFolderUtils::CreateFolder solves that problem by creating the parent folders and then the specified folder itself.

The DeleteDirectory WIN32 API will fail to delete a folder as long there are sub-folders for that one. Thus, CFolderUtils::RemoveFolder solves that problem by removing recursively the sub-folders and after that the specified folder.

CFolderUtils::GetSpace recursively calculates a folder size.

CFolderUtils::CopyFolder uses SHFileOperation for copying a folder along with its sub-folders.

Whole four functions are implemented in FolderUtils.h as static functions to CFolderUtils.

Example

#include "FolderUtils.h"

void main()
{
    CFolderUtils::CreateFolder("C:\\AA\\BB\\CC\\DD");
    int Size = CFolderUtils::GetSize("C:\\AA");
}

History

  • 1-Feb-2005 - Fixed a bug in CreateFolder function.
  • 2-Feb-2005 - Fixed a bug in GetSpace that discarded folders that begin with "." and add a UNICODE support in RemoveFolder.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here