Use ::SHFileOperation() as I suggested in my previous post, it will also delete folder and all it subfolders.Quote:
Originally Posted by roger5089
Cheers
Printable View
Use ::SHFileOperation() as I suggested in my previous post, it will also delete folder and all it subfolders.Quote:
Originally Posted by roger5089
Cheers
thank's you suggestionQuote:
Originally Posted by VictorN
the problem is how can i 'DeleteDirectory' 'const char [8]' convert 'LPCTSTR'
Code:
bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true)
{
int len = _tcslen(lpszDir);
TCHAR *pszFrom = new TCHAR[len+2];
_tcscpy(pszFrom, lpszDir);
pszFrom[len] = 0;
pszFrom[len+1] = 0;
SHFILEOPSTRUCT fileop;
fileop.hwnd = NULL; // no status display
fileop.wFunc = FO_DELETE; // delete operation
fileop.pFrom = pszFrom; // source file name as double null terminated string
fileop.pTo = NULL; // no destination needed
fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; // do not prompt the user
if(!noRecycleBin)
fileop.fFlags |= FOF_ALLOWUNDO;
fileop.fAnyOperationsAborted = FALSE;
fileop.lpszProgressTitle = NULL;
fileop.hNameMappings = NULL;
int ret = SHFileOperation(&fileop);
delete [] pszFrom;
return (ret == 0);
}
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 並於失敗時列印錯誤
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 配合您的需要變更錯誤碼
_tprintf(_T("嚴重錯誤: MFC 初始化失敗\n"));
nRetCode = 1;
}
else
{
// TODO: 在此撰寫應用程式行為的程式碼。
DeleteDirectory("d:\\Test", false);
}
return nRetCode;
}
Typecast it,
Code:DeleteDirectory((LPCTSTR) _T("d:\\Test"), false);
Thank's your help , but i found the problem of this function , which is delete all folder data , not just delete that folder insite data?
Your question is not clear; please explain what exactly you want to achieve.Quote:
Originally Posted by roger5089
Cheers