Here is an update to the code so that it will correctly identify a directory...Instead of using the . as a determinant
Code:
#include<iostream>
#include<string>
#include <windows.h>
using namespace std;
void DeleteFolder( const char *szFolderPath)
{
string strFileFilter;
strFileFilter = szFolderPath;
strFileFilter += "\\*.*";
WIN32_FIND_DATA win32FindData; //struct to hold file information
HANDLE hFile = FindFirstFile(strFileFilter.c_str(), &win32FindData);
while( FindNextFile(hFile, &win32FindData) )
{
string strFilePath; // full file path
string strFileName; // file name with extension only
strFilePath = szFolderPath;
strFilePath += "\\";
strFilePath += win32FindData.cFileName;
strFileName = win32FindData.cFileName;
//If is dots
if( strFileName == "." ||
strFileName == "..")
{
continue;
}
//Check to see if it is a directory
if( win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) //not extension
{
//Recursive call
DeleteFolder( strFilePath.c_str() );
}
else
{
DeleteFile(strFilePath.c_str());
}
}
FindClose( hFile ); //release handle otherwise dir cannot be removed
RemoveDirectory( szFolderPath );
}
int main(void)
{
string strDir;
while(1)
{
cout << "\nEnter dir path or \"quit\" to exit: " << endl;
cin >> strDir;
if( strDir == "quit" )
break;
DeleteFolder( strDir.c_str() );
}
return 0;
}