Hello, I have recently been able to delete files using this code(With the aid of others from the forum) And I was wondering how you can change this, to suit deleting a folder

#include <iostream>
#include <windows.h>
int main(int argc, const char * argv[])

	// Get a pointer to the file name/path
	const char * pFileToDelete = "c:\\Program Files\\myfile.txt";

	// try deleting it using DeleteFile
	if(DeleteFile(pFileToDelete ))

		// succeeded
		std::cout << "Deleted file"  << std::endl;
		// failed
		std::cout << "Failed to delete the file" << std::endl;
	return 0;

Thank you

You need to get a good Win32 reference.

The function you want is BOOL RemoveDirectory( LPCTSTR lpPathName ); The directory must be empty and your program must have permissions to delete it. If the function fails it returns zero, else it returns non-zero.

Hope this helps.

similar to how there are all the windows functions to work with files, there are ones to handle directories.

unfortunately there is no direct way, first you must delete all the files within the directory.
for this you need to find all the files in the folder.

microsoft are nice enough to give you this code in an example though.

store the filenames in an array of strings or something, loop through that array with deletefile function.

then its simple to use removedirectory function

MSDN is your friend =D

its working guys its working thanks a lot mr.daniweb. for make my problem clear.

commented: Don't bump old threads -1

hi friends. i want to delete a folder using c or cpp.

commented: You can't be serious...? +0