diff options
Diffstat (limited to 'CPP/Windows/FileDir.cpp')
| -rw-r--r-- | CPP/Windows/FileDir.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/CPP/Windows/FileDir.cpp b/CPP/Windows/FileDir.cpp index 2cb83b2..10c4e98 100644 --- a/CPP/Windows/FileDir.cpp +++ b/CPP/Windows/FileDir.cpp | |||
| @@ -651,6 +651,35 @@ bool RemoveDirWithSubItems(const FString &path) | |||
| 651 | return RemoveDir(path); | 651 | return RemoveDir(path); |
| 652 | } | 652 | } |
| 653 | 653 | ||
| 654 | bool RemoveDirAlways_if_Empty(const FString &path) | ||
| 655 | { | ||
| 656 | const DWORD attrib = NFind::GetFileAttrib(path); | ||
| 657 | if (attrib != INVALID_FILE_ATTRIBUTES | ||
| 658 | && (attrib & FILE_ATTRIBUTE_READONLY)) | ||
| 659 | { | ||
| 660 | bool need_ClearAttrib = true; | ||
| 661 | if ((attrib & FILE_ATTRIBUTE_REPARSE_POINT) == 0) | ||
| 662 | { | ||
| 663 | FString s (path); | ||
| 664 | s.Add_PathSepar(); | ||
| 665 | NFind::CEnumerator enumerator; | ||
| 666 | enumerator.SetDirPrefix(s); | ||
| 667 | NFind::CDirEntry fi; | ||
| 668 | if (enumerator.Next(fi)) | ||
| 669 | { | ||
| 670 | // we don't want to change attributes, if there are files | ||
| 671 | // in directory, because RemoveDir(path) will fail. | ||
| 672 | need_ClearAttrib = false; | ||
| 673 | // SetLastError(ERROR_DIR_NOT_EMPTY); | ||
| 674 | // return false; | ||
| 675 | } | ||
| 676 | } | ||
| 677 | if (need_ClearAttrib) | ||
| 678 | SetFileAttrib(path, 0); // we clear read-only attrib to remove read-only dir | ||
| 679 | } | ||
| 680 | return RemoveDir(path); | ||
| 681 | } | ||
| 682 | |||
| 654 | #endif // _WIN32 | 683 | #endif // _WIN32 |
| 655 | 684 | ||
| 656 | #ifdef UNDER_CE | 685 | #ifdef UNDER_CE |
