| Previous | Next |
| STATUS_VARIABLE_NOT_FOUND | STATUS_FILE_CORRUPT_ERROR |
STATUS_DIRECTORY_NOT_EMPTY
STATUS_DIRECTORY_NOT_EMPTY is returned when a delete operation targets a directory that still contains entries. Removing a directory is not the same as recursively deleting a tree: the directory must be empty before the final removal can succeed.
What “empty” requires
The caller must account for ordinary files and child directories, but also for concurrent activity. Another process can create a new entry between enumeration and deletion, and a handle can keep a directory in use while cleanup is still in progress. Windows documents that a directory removal is completed when the relevant handles are closed, so lifecycle and sharing rules can matter as well as the visible contents.
Reliable cleanup strategy
- Enumerate and delete child entries deliberately; do not expect
RemoveDirectoryto recurse. - Handle reparse points and symbolic links according to the intended policy, rather than following them accidentally.
- Re-enumerate before the final delete when another process can modify the tree.
- Log the remaining entry names and the operation that created them; a generic retry hides the reason the directory is non-empty.
For user-facing cleanup, distinguish a real content problem from an access or sharing problem. A directory that cannot be removed because it is non-empty requires different remediation than one blocked by permissions or an incompatible open handle.
See Creating and Deleting Directories and RemoveDirectory.
Looking for a different code? Search another status or error code.
