[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

"Directory is not empty" error message when deleting directory

Posted on 2010-11-17
1
Medium Priority
?
556 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 2000 total points
ID: 34158316
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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