static bool DeleteEmptyFolderAndEmptySubFolders(const FString &path) { NFind::CFileInfo fileInfo; FString pathPrefix = path + FCHAR_PATH_SEPARATOR; { NFind::CEnumerator enumerator; enumerator.SetDirPrefix(pathPrefix); while (enumerator.Next(fileInfo)) { if (fileInfo.IsDir()) if (!DeleteEmptyFolderAndEmptySubFolders(pathPrefix + fileInfo.Name)) return false; } } /* // we don't need clear read-only for folders if (!MySetFileAttributes(path, 0)) return false; */ return RemoveDir(path); }
HRESULT CDirItems::EnumerateDir(int phyParent, int logParent, const FString &phyPrefix) { RINOK(ScanProgress(phyPrefix)); NFind::CEnumerator enumerator; enumerator.SetDirPrefix(phyPrefix); for (unsigned ttt = 0; ; ttt++) { NFind::CFileInfo fi; bool found; if (!enumerator.Next(fi, found)) { return AddError(phyPrefix); } if (!found) return S_OK; int secureIndex = -1; #ifdef _USE_SECURITY_CODE if (ReadSecure) { RINOK(AddSecurityItem(phyPrefix + fi.Name, secureIndex)); } #endif AddDirFileInfo(phyParent, logParent, secureIndex, fi); if (Callback && (ttt & kScanProgressStepMask) == kScanProgressStepMask) { RINOK(ScanProgress(phyPrefix)); } if (fi.IsDir()) { const FString name2 = fi.Name + FCHAR_PATH_SEPARATOR; unsigned parent = AddPrefix(phyParent, logParent, fs2us(name2)); RINOK(EnumerateDir(parent, parent, phyPrefix + name2)); } } }