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

This article has been dead for over six months. Start a new discussion instead.