Click here to Skip to main content
15,891,204 members
Articles / Desktop Programming / MFC
Article

Folder utilities

Rate me:
Please Sign up or sign in to vote.
1.60/5 (21 votes)
31 Jan 2005 69.7K   1.2K   32   17
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


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhat about '/' ? Pin
jolindien17-Oct-07 23:33
jolindien17-Oct-07 23:33 
AnswerRe: What about '/' ? Pin
jolindien18-Oct-07 0:02
jolindien18-Oct-07 0:02 
GeneralPerfect! Pin
flippydeflippydebop2-Aug-07 9:53
flippydeflippydebop2-Aug-07 9:53 
QuestionCopyFolder() Uses Literals - CString vars won't work? Pin
alan937-Feb-07 8:17
alan937-Feb-07 8:17 
AnswerRe: CopyFolder() Uses Literals - CString vars won't work? Pin
Dudi Avramov7-Feb-07 22:32
Dudi Avramov7-Feb-07 22:32 
GeneralRe: CopyFolder() Uses Literals - CString vars won't work? Pin
alan938-Feb-07 1:59
alan938-Feb-07 1:59 
GeneralRe: CopyFolder() Uses Literals - CString vars won't work? Pin
Dudi Avramov10-Feb-07 22:14
Dudi Avramov10-Feb-07 22:14 
QuestionWill it work for Poket PCs with Windows CE 5.0? Pin
MaheshKalose10-Nov-06 21:18
MaheshKalose10-Nov-06 21:18 
Jokeis Good Pin
Vladmorosan23-Mar-06 20:33
Vladmorosan23-Mar-06 20:33 
Generalnot bad, but... Pin
S.Cartwright8-May-05 21:09
S.Cartwright8-May-05 21:09 
GeneralRe: not bad, but... Pin
Dudi Avramov9-May-05 21:51
Dudi Avramov9-May-05 21:51 
The idea was to avoid recursion calls.
GeneralSome issues that need to be addressed Pin
.:floyd:.1-Feb-05 15:36
.:floyd:.1-Feb-05 15:36 
GeneralRe: Some issues that need to be addressed Pin
Dudi Avramov1-Feb-05 20:44
Dudi Avramov1-Feb-05 20:44 
QuestionDependencies? Pin
Don Clugston24-Jan-05 19:53
Don Clugston24-Jan-05 19:53 
AnswerRe: Dependencies? Pin
russeller23-Nov-05 10:15
russeller23-Nov-05 10:15 
Generalusefull code Pin
Sudhir Mangla24-Jan-05 18:01
professionalSudhir Mangla24-Jan-05 18:01 
GeneralYou should reconsider some methods... Pin
Markus Hlacer24-Jan-05 4:28
Markus Hlacer24-Jan-05 4:28 

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.