VC++ 删除整个文件夹

int CPublic::removeDir(CString lpszPath) { lpszPath += '/0'; SHFILEOPSTRUCT FileOp; FileOp.fFlags = FOF_NOCONFIRMATION; FileOp.hNameMappings = NULL; FileOp.hwnd = NULL; FileOp.lpszProgressTitle = NULL; FileOp.pFrom = lpszPath; FileOp.pTo = NULL; FileOp.wFunc = FO_DELETE; if ( SHFileOperation( &FileOp ) == 0 ) return NOT_ERROR; else return DEL_TREE_ERROR; }

意见:
CString strWorkAreaPath; char path[MAX_PATH]; strcpy(path,"E://文件夹//aa.txt"); SetCurrentDirectory(_T("C://")); strWorkAreaPath = path; strWorkAreaPath += '/0'; SHFILEOPSTRUCT fileop; fileop.fFlags = FOF_ALLOWUNDO ; fileop.hwnd = NULL; fileop.pFrom = strWorkAreaPath; fileop.pTo = NULL; fileop.wFunc = FO_DELETE; fileop.fAnyOperationsAborted = TRUE; fileop.hNameMappings = NULL; fileop.lpszProgressTitle = _T("正在删除文件"); // fileop.fFlags &= ~FOF_ALLOWUNDO; SHFileOperation(&fileop);
这样才叫删除文件,你的代码是删除文件夹

注意:
关键在于,lpszPath 如 "d://aaaa//TFG/0" 必须有个"/0",但是用 lpszPath = lpszPath + "/0"的办法加不上。

你可能感兴趣的:(VC++程序设计)