Tuesday, 22 October 2013

The directory is not empty cannot delete error


I got error The directory is not empty cannot delete while deleting some folders in my Windows 8 machine. but when check the folder, I don't find any suspected files regarding error this error. I have deleted many times this kind of folders with lot files inside, but today only I got this error.

Solution - The directory is not empty cannot delete:

After I have googled and analyzed, I noticed the reason for this error is due to Hidden files which are inside the folders.

try to delete folder with this command

rmdir /s C:\Users\YourFolder\folder
- or -
rmdir /s/q C:\Users\YourFolder\folder

Solution - The directory is not empty cannot delete in C# :

If you got this error while deleting folder from C# code you need to use following code to set folder attributes into Normal.

File.SetAttributes(target_dir, FileAttributes.Normal);
Directory.Delete(target_dir, false);

Useful References:




Software Developer


No comments:

Post a Comment