0

I have code that creates a temp directory, does stuff, and then deletes the directory when it is done. The problem is that even though I specify true for the recursive parameter, it still throws an IOException saying "The directory is not empty". Here's what I have for code:

DirectoryInfo info = Directory.CreateDirectory(Path.Combine(tempdir, "temp"));
try{
    PopulateDir(info);
    foreach (FileInfo file in info.EnumerateFiles("*.*", SearchOption.AllDirectories)){
        DoStuff(file);
    }
}
finally{
    info.Delete(true);// note: this is apparently functionally identical to Directory.Delete(info.FullName, true)
}

1 Answer 1

1

It appears that info.EnumerateFiles was the issue. I got that idea from this answer. I switched that to info.GetFiles and I was then able to delete the directory after.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.