#include <io.h> #include <stdio.h> #include <string> #include <direct.h> void emptydir(const char* szDir) { if (szDir == NULL || strlen(szDir) == 0) return; std::string str = std::string(szDir) + "/*.*"; struct _finddata_t fd; long h=_findfirst(str.c_str(), &fd); if (h == -1) { return ; } do { if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0) continue; if (fd.attrib & (_A_SYSTEM | _A_HIDDEN)) continue; if (fd.attrib & _A_SUBDIR) { std::string str = std::string(szDir) + "/" + fd.name + "/"; emptydir(str.c_str()); rmdir(str.c_str()); continue; } std::string str = std::string(szDir) + fd.name; printf("%s\n", str.c_str()); remove(str.c_str()); } while (_findnext(h, &fd)==0); _findclose(h); }
时间: 2024-10-14 08:38:28