Solved

"Directory is not empty" error message when deleting directory

Posted on 2010-11-17
1
497 Views
Last Modified: 2012-06-21
I have a simple function for creating a directory, check first to see if the directory already exists.  If it does, delete it.

I keep getting the error message "the directory is not empty", but I specify that the recursive parameter is TRUE, which should delete these subdirectories/files...

Am I missing something?

 
protected void CreateDirectory(string target_directory)
    {
        try
        {
            if (Directory.Exists(target_directory))
            {
                try
                {
                    lblOutput.Text += "<br />deleting directory: " + target_directory;
                    Directory.Delete(target_directory, true);
                }
                catch (Exception Ex)
                {
                    Session["error_message"] += "<br />Error deleting " + target_directory + ": " + Ex.Message;
                    throw (Ex);
                }
            }

            try
            {
                Directory.CreateDirectory(target_directory);
            }
            catch (Exception Ex)
            {
                Session["error_message"] += "<br />Error creating directory (" + target_directory + "): " + Ex.Message;
            }
        }
        catch (Exception Ex)
        {
            Session["error_message"] += "<br />Error during CreateDirectory(" + target_directory + "): " + Ex.Message;
            throw (Ex);
        }
    }

Open in new window

0
Comment
Question by:quipuha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 30

Accepted Solution

by:
Reza Rad earned 500 total points
ID: 34158316
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pressing download button in c# 7 45
Selenium and Xpath 4 65
C# rename a class and update all references efficiently 6 47
How does this modal gets closed? 6 38
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question