Click here to Skip to main content
Click here to Skip to main content

Delete folders, subfolders and files easily

By , 20 Feb 2002
 
<!-- Add the rest of your HTML here -->

Introduction

I Created this to show you how to delete all the files and subfolders in a selected folder including subfolders. It's very easy to understand and it's all by using the MFC (CFileFind, with some API functions)

void RecursiveDelete(CString szPath)
{
	CFileFind ff;
	CString path = szPath;
	
	if(path.Right(1) != "\\")
		path += "\\";

	path += "*.*";

	BOOL res = ff.FindFile(path);

	while(res)
	{
		res = ff.FindNextFile();
		if (!ff.IsDots() && !ff.IsDirectory())
			DeleteFile(ff.GetFilePath());
		else if (ff.IsDirectory())
		{
			path = ff.GetFilePath();
			RecursiveDelete(path);
			RemoveDirectory(path);
		}
	}
}

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

About the Author

No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5 PinmemberRahul (Software Engineer)28-Sep-12 3:07 
Generalthank you, I used it on Win CE [modified] Pinmemberjuankre2-Oct-11 10:22 
GeneralMultiple File Creation/Deletion PinmemberRockSai30-Nov-08 6:03 
GeneralCannot delete folder Pinmemberatans9-Jul-07 16:30 
GeneralRe: Cannot delete folder Pinmemberatans9-Jul-07 18:16 
Generalone condition is missing Pinmemberbjdodo7-Feb-07 5:12 
QuestionWhy its not deleting the folders which contsins files? PinmemberRaoSanthosh7-Sep-06 3:21 
GeneralI get an infinte loop with this code Pinmemberhaleyana24-May-04 7:03 
GeneralRe: I get an infinte loop with this code Pinmemberandyvinc24-May-04 8:03 
GeneralRe: I get an infinte loop with this code PinsussAnonymous20-May-05 3:27 
GeneralDeleting file folder after reboot PinmemberBalkrishna Talele20-Apr-04 20:55 
GeneralRemoveDirectory() not found Pinmembersatya19756-Nov-03 5:45 
GeneralRe: RemoveDirectory() not found PinmemberRavi Bhavnani6-Nov-03 6:29 
GeneralI have found it Pinmembersatya19756-Nov-03 6:52 
GeneralDeleteFile() may fail. PinsussAnonymous9-Dec-02 9:20 
GeneralFinally one that works! PinmemberAnonymous26-Feb-02 2:36 
GeneralRe: Finally one that works! PinmemberAnonymous16-May-02 3:51 
GeneralRe: Finally one that works! PinmemberFess66219-Feb-04 21:50 
GeneralRe: Finally one that works! Pinmembersfeldi1-Mar-04 22:03 
GeneralRe: Finally one that works! PinsussAnonymous11-Oct-05 2:27 
QuestionDeleted files ----> recycle bin ??? PinmemberAnonymous26-Feb-02 0:14 
AnswerRe: Deleted files ----> recycle bin ??? PinmemberMustafa Demirhan27-Feb-02 20:36 
Generalthanks PinmemberMazdak21-Feb-02 23:13 
QuestionIs this the easy way???? PinmemberMustafa Demirhan21-Feb-02 16:46 
AnswerRe: Is this the easy way???? PinmemberBLaZiNiX21-Feb-02 16:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 21 Feb 2002
Article Copyright 2002 by Jonathan Pouliot
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid