MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / rmDir

Function rmDir

src/OSspecific/POSIX/POSIX.C:1008–1089  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1006
1007
1008bool Foam::rmDir(const fileName& directory)
1009{
1010 if (POSIX::debug)
1011 {
1012 //InfoInFunction
1013 Pout<< FUNCTION_NAME << " : removing directory " << directory << endl;
1014 if ((POSIX::debug & 2) && !Pstream::master())
1015 {
1016 error::printStack(Pout);
1017 }
1018 }
1019
1020 // Pointers to the directory entries
1021 DIR *source;
1022 struct dirent *list;
1023
1024 // Attempt to open directory and set the structure pointer
1025 if ((source = ::opendir(directory.c_str())) == nullptr)
1026 {
1027 WarningInFunction
1028 << "cannot open directory " << directory << endl;
1029
1030 return false;
1031 }
1032 else
1033 {
1034 // Read and parse all the entries in the directory
1035 while ((list = ::readdir(source)) != nullptr)
1036 {
1037 fileName fName(list->d_name);
1038
1039 if (fName != "." && fName != "..")
1040 {
1041 fileName path = directory/fName;
1042
1043 if (path.type(false) == fileName::DIRECTORY)
1044 {
1045 if (!rmDir(path))
1046 {
1047 WarningInFunction
1048 << "failed to remove directory " << fName
1049 << " while removing directory " << directory
1050 << endl;
1051
1052 ::closedir(source);
1053
1054 return false;
1055 }
1056 }
1057 else
1058 {
1059 if (!rm(path))
1060 {
1061 WarningInFunction
1062 << "failed to remove file " << fName
1063 << " while removing directory " << directory
1064 << endl;
1065

Callers 7

mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
loadOrCreateMesh.CFile · 0.50

Calls 3

printStackFunction · 0.70
rmFunction · 0.70
typeMethod · 0.45

Tested by 1

mainFunction · 0.40