2007年4月23日 星期一

DeleteDir

TCHAR temp[MAX_PATH]={0};
_tcscpy(temp,path);
temp[path.GetLength()+1]=NULL;
SHFILEOPSTRUCT fo;
int nSuccessCode=0;
ZeroMemory(&fo, sizeof(fo));
fo.fFlags = FOF_ALLOWUNDO + FOF_NOCONFIRMATION + FOF_SILENT;
fo.wFunc = FO_DELETE; // delete contents of this folder
fo.pFrom = (LPCTSTR)temp;
fo.pTo = NULL;
nSuccessCode = SHFileOperation(&fo);
return nSuccessCode;

最後的return值在某種情況下會是1026(失敗)
搞了半天才發現不能是\結尾 把\拿掉就好了
網路上其他人碰到的狀況則多是字串沒有以兩個NULL做結尾