void IMVLFile::RmFolder(const string& dir) { CleanFolder(dir); if (FolderExist(dir)) ; //RunProgram("Cmd.exe", format("/c rmdir /s /q \"%s\"", _S(dir)), true, false); }
void CleanFolder(const fs::path& rPath, bool isTop) { assert(fs::is_directory(rPath)); fs::directory_iterator end_iter; // First recursively remove the children for (fs::directory_iterator dir_iter(rPath); dir_iter != end_iter; ++dir_iter) { if (fs::is_directory(dir_iter->status())) { CleanFolder(dir_iter->path(), false); } else { const fs::path& r_item_path(dir_iter->path()); if (!isTop || PATH_LEAF_NAME(r_item_path)[0] != '.') { fs::remove(r_item_path); } } } // Now remove the folder itself, if not top if (!isTop) { fs::remove(rPath); } }
void CmFile::CleanFolder(CStr& dir, bool subFolder) { vecS names; int fNum = CmFile::GetNames(dir + "/*.*", names); for (int i = 0; i < fNum; i++) RmFile(dir + "/" + names[i]); vecS subFolders; int subNum = GetSubFolders(dir, subFolders); if (subFolder) for (int i = 0; i < subNum; i++) CleanFolder(dir + "/" + subFolders[i], true); }
void IMVLFile::CleanFolder(const string& dir, bool subFolder) { vector<string> names; int fNum = IMVLFile::GetNames(dir + "/*.*", names); for (int i = 0; i < fNum; i++) RmFile(dir + "/" + names[i]); vector<string> subFolders; int subNum = GetSubFolders(dir, subFolders); if (subFolder) for (int i = 0; i < subNum; i++) CleanFolder(dir + "/" + subFolders[i], true); }
void OutputFileHandler::CommonConstructor(const std::string& rDirectory, bool cleanOutputDirectory) { // Is it a valid request for a directory? if (rDirectory.find("..") != std::string::npos) { EXCEPTION("Will not create directory: " + rDirectory + " due to it potentially being above, and cleaning, CHASTE_TEST_OUTPUT."); // Note: in Boost 1.48 and above we could use 'canonical' to check this better } //The notion of absolute path on Windows is rather different. //For example, / and /foo are not absolute paths. //However, fs::path.has_root_path() captures the intended semantics here as follows if (fs::path(rDirectory).has_root_path()) { EXCEPTION("The constructor argument to OutputFileHandler must be a relative path; '" << rDirectory << "' is absolute."); } mDirectory = MakeFoldersAndReturnFullPath(rDirectory); // Clean the directory (default) if (rDirectory != "" && cleanOutputDirectory) // Clean directory but don't ever clean CHASTE_TEST_OUTPUT at the top level { FileFinder signature_file(mDirectory + SIG_FILE_NAME, RelativeTo::Absolute); if (!signature_file.Exists()) { EXCEPTION("Cannot delete " + mDirectory + " because signature file \"" + SIG_FILE_NAME + "\" is not present."); } // Are we the master process? Only the master should delete files if (PetscTools::AmMaster()) { CleanFolder(mDirectory); } // Wait for master to finish before going on to use the directory. PetscTools::Barrier("OutputFileHandler"); } }
bool DeleteFolder(const KString& FolderName, bool bRecursive, bool bSafe) { if(!CleanFolder(FolderName, bRecursive, bSafe)) return false; if(!GetCurrentFolder().CollateNoCase(SlashedFolderName(FolderName))) _tchdir(TEXT("..")); if(_trmdir(UnslashedFolderName(FolderName))) { if(!bSafe) { INITIATE_DEFINED_CODE_FAILURE( (KString)TEXT("Error deleteing folder \"") + FolderName + TEXT("\""), errno); } return false; } return true; }
void CmFile::RmFolder(CStr& dir) { CleanFolder(dir); if (FolderExist(dir)) RunProgram("Cmd.exe", format("/c rmdir /s /q \"%s\"", _S(dir)), true, false); }