Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:00:37+00:00 2026-06-15T22:00:37+00:00

Windows 7 x64 SP1 .NET Framework 3.5 SP1 I have wrote simple code, but

  • 0

Windows 7 x64 SP1
.NET Framework 3.5 SP1

I have wrote simple code, but it works through time, the exception occurs at every second pass.
… I.e.: it works fine for the even starts: 2, 4, 6, 8, e.t.c., but I get exception for odd starts: 1, 3, 5, 7, 9, e.t.c.

// localMenuDirName is 'GPSM\AdminCAD'.
DirectoryInfo menuDir = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(
    Environment.SpecialFolder.Programs), localMenuDirName));
if (menuDir.Exists) {
    FileInfo[] files = menuDir.GetFiles("*", SearchOption.AllDirectories);
    foreach (FileInfo file in files) {
        file.IsReadOnly = false;
    }
    sb.AppendLine(String.Format("We begin deleting the '{0}' directory", menuDir.FullName));

    Directory.Delete(menuDir.FullName, true); // Get Exception here

    // menuDir.Delete(true); // here I get same exception.

Output text:

We begin deleting the ‘C:\Users\andrey.bushman\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\GPSM\AdminCAD’ directory

Exception: The directory is not empty.

But directory is empty (all files already deleted). I open explorer and see it.

Next code works fine always:

// localMenuDirName is 'GPSM\AdminCAD'.
DirectoryInfo menuDir = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(
    Environment.SpecialFolder.Programs), localMenuDirName));
if (menuDir.Exists) {
    FileInfo[] files = menuDir.GetFiles("*", SearchOption.AllDirectories);
    foreach (FileInfo file in files) {
        file.IsReadOnly = false;
    }
    sb.AppendLine(String.Format("We begin deleting the '{0}' directory", menuDir.FullName));

    try {
        Directory.Delete(menuDir.FullName, true); 
    }
    catch {
        // Try again... Now it works without exception!
        Directory.Delete(menuDir.FullName, true);
    }
    sb.AppendLine("Operation was executed successfully.");

Why it is happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:00:38+00:00Added an answer on June 15, 2026 at 10:00 pm

    There are different possible options, where the Directory.Delete can fail with IOException.
    According to MSDN

    A file with the same name and location specified by path exists.

    -or- The directory specified by path is read-only, or recursive is false and path is not an empty directory.

    -or- The directory is the application’s current working directory.

    -or- The directory contains a read-only file.

    -or- The directory is being used by another process. There is an open handle on the directory or on one of its files, and the operating system is Windows XP or earlier. This open handle can result from enumerating directories and files. For more information, see How to: Enumerate Directories and Files.

    In other words: check for open handlers to that directory, check for hidden files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a new WIndows Server 2008 R2 x64 DataCentre with Framework 3.5 SP1
I'm running Windows 7 - x64 Edition with IIS 7.5 I have a simple
I'm using Windows Vista x64 with SP1, and I'm developing an ASP.NET app with
I have installed jdk-7u7-windows-x64 on my windows 7 (64 bit) machine, but when I
I am having Windows 7 x64 SP1. I have downloaded symbols from: http://msdn.microsoft.com/en-us/windows/hardware/gg463028 I
The problem is the following: On Windows x64, pointers are 64-bit, but type long
I have a 32-bit application that must run on a Windows x64 server using
We are observing 4-6 threads on Windows 7 x64 in the application which have
After watching in horror as the .NET framework 3.5 SP1 bloated to whopping 231
I have an application build with VS2008 SP1a (9.0.30729.4148) on Windows 7 x64 that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.