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;
	}
	else
	{
		// failed
		std::cout << "Failed to delete the file" << std::endl;
	}
	std::cin.get();
	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.
http://msdn2.microsoft.com/en-us/library/aa363950(VS.85).aspx

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.
http://msdn2.microsoft.com/en-us/library/aa365200(VS.85).aspx

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

then its simple to use removedirectory function
http://msdn2.microsoft.com/en-us/library/aa365488(VS.85).aspx

MSDN is your friend =D
Dead.Rabit

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.