diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2025-07-05 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2025-07-05 19:27:33 +0500 |
| commit | 395149956d696e6e3099d8b76d797437f94a6942 (patch) | |
| tree | 6ed5013a637078ae2dfdc4acf1ad93bf29cea356 /CPP/Windows/FileDir.cpp | |
| parent | e5431fa6f5505e385c6f9367260717e9c47dc2ee (diff) | |
| download | 7zip-25.00.tar.gz 7zip-25.00.tar.bz2 7zip-25.00.zip | |
25.0025.00
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 |
