Windows C/C++ 直接删除目录(子目录、文件) —— SHFILEOPSTRUCT

使用方法:

SHFILEOPSTRUCT DirRemove; 

DirRemove.fFlags = FOF_NOCONFIRMATION; 

DirRemove.hNameMappings = NULL; 

DirRemove.hwnd = NULL; 

DirRemove.lpszProgressTitle = NULL; 

DirRemove.pFrom = "D:\\MyBlog"

DirRemove.pTo = NULL; 

DirRemove.wFunc = FO_DELETE; 

SHFileOperation(&DirRemove); 

注意点:

FileOp.pFrom这个参数,它使用的字符串一定是要'\0'结尾的,

"D:\\MyBlog"这个字符串默认的结束字符就是'\0',

如果像下面这样写的话就会出错:

std::string delPath = "D:\\MyBlog";

FileOp.pFrom = delPath.c_str(); 

string变量转化为CHAR[] 再使用


猜你喜欢

转载自blog.csdn.net/qq_37061368/article/details/79412498