WIN32_FIND_DATA fileFind;
HANDLE hFirstFile;
CString strFolder = "TargetFolder";
CString strCurrentDir,strForeDir;
int flagFind = 0;
CString strdir;
char buf[MAX_PATH];
int nIndex;
memset(buf,0,MAX_PATH);
GetCurrentDirectory(MAX_PATH,buf);
strCurrentDir.Format(_T("%s"),buf);
strForeDir = strCurrentDir;
nIndex = strForeDir.ReverseFind('\\');
strForeDir.Delete(nIndex+1,strForeDir.GetLength()-nIndex-1);
strdir = strForeDir + _T("*");
hFirstFile = FindFirstFile(strdir,&fileFind);
do {
CString strText;
strText.Format(_T("%s"),fileFind.cFileName);
if(strText == strFolder)
{
flagFind = 1;
AfxMessageBox(strForeDir + strFolder + ":The folder is exist.");
}
} while(FindNextFile(hFirstFile,&fileFind));
if(flagFind == 0)
{
if(!CreateDirectory(strForeDir + strFolder,NULL))
{
AfxMessageBox("Create folder error!");
return;
}
SetCurrentDirectory(strForeDir + strFolder);
CFile file;
char str[] = "if you want show someting in the program you should add some txt file in to current folder ";
file.Open("readme.txt",CFile::modeCreate | CFile::modeWrite,NULL);
file.Write(str,strlen(str));
file.Close();
}