WSAENOTEMPTY - 10066 (0x2752)

Cannot remove a directory that is not empty.

Updated: Feb 21, 2026

Technical Background

The WSAENOTEMPTY error code is returned by the Windows Sockets (Winsock) API when an attempt to remove a directory fails because it contains files or subdirectories. This error indicates that the operation cannot proceed due to the presence of non-empty content within the specified directory.

Error Details

  • Error Name: WSAENOTEMPTY
  • Numeric Code: 10066 (0x2752)
  • Short Description: Indicates that a directory cannot be removed because it is not empty.

Common Causes

The error WSAENOTEMPTY typically occurs when the following conditions are met:

  • An attempt to remove a directory using functions such as DeleteFile, RemoveDirectory, or similar operations in Winsock.
  • The specified directory contains files, subdirectories, or other non-empty content that prevents its removal.

Real-World Context

This error is commonly encountered when managing file systems and directories programmatically. It can occur in various scenarios such as cleaning up temporary files, performing data migrations, or implementing automated backup solutions.

Is This Error Critical?

The criticality of this error depends on the context in which it occurs. In most cases, it is not a critical failure but rather an informational message indicating that the operation cannot be completed as requested. However, if the application relies on the removal of non-empty directories for its functionality, this error could indicate a potential issue with the data or directory structure.

How to Diagnose

To diagnose and understand why WSAENOTEMPTY is being returned, consider the following steps:

  1. Review Operation Context: Ensure that the operation context is correct and that the target directory is indeed the one intended for removal.
  2. Validate Parameters: Verify that all parameters passed to the function are valid and correctly identify the directory path.
  3. Confirm Object Types: Confirm that the object being operated on is a directory and not a file or other type of object.
  4. Verify Input Data: Check if there are any files or subdirectories within the specified directory that might be preventing its removal.
  5. Check Limits or Constraints: Ensure that no system limits or constraints are in place that could affect the operation, such as permissions or resource availability.

How to Resolve

To resolve the WSAENOTEMPTY error and successfully remove a non-empty directory, consider the following steps:

  1. Correct Parameter Usage: Ensure that all parameters used in the function call are correct and accurately represent the intended directory path.
  2. Adjust Operation Context: If necessary, adjust the operation context to ensure that only empty directories or files are targeted for removal.
  3. Restore Data: If there is a need to remove non-empty content, consider backing up any important data before proceeding with the removal.
  4. Retry Operation with Valid Inputs: Attempt to perform the operation again with valid inputs and ensure that all conditions required for successful directory removal are met.

Developer Notes

When working with file system operations in Windows using Winsock APIs, it is essential to handle WSAENOTEMPTY errors gracefully. This error should be treated as an informational message rather than a critical failure, allowing the application to continue execution or provide appropriate feedback to the user.

Related Errors

  • Error 120 (ENOENT): No such file or directory. This error might occur if the specified directory does not exist.
  • Error 53 (ENOTDIR): Not a directory. This error occurs when the path provided is not a valid directory.
  • Error 66 (EEXIST): File exists. This error can occur if attempting to create a file that already exists.

FAQ

Q: What does WSAENOTEMPTY mean?

A: WSAENOTEMPTY indicates that the operation of removing a directory cannot proceed because it is not empty.

Q: How do I handle this error in my application?

A: Handle the error by ensuring that all directories are empty before attempting to remove them. If necessary, provide feedback to the user and allow for manual intervention or data backup.

Q: Can WSAENOTEMPTY be ignored?

A: In most cases, WSAENOTEMPTY can be treated as an informational message rather than a critical failure. However, it is important to ensure that all necessary steps are taken to handle the error appropriately.

Summary

The WSAENOTEMPTY error code in Windows API indicates that a directory cannot be removed because it contains non-empty content. This error should be handled by ensuring that directories are empty before attempting removal or providing appropriate feedback and handling mechanisms within the application.