none
Directory.Delete is neither deleting or nor raising the exception RRS feed

  • Question

  • Hi,

        I came through some strange scenario, where Directory.Delete is not raising the exception and at the same time not deleting the folder. 

    Before we delete the folder, all the files in the folders are deleted. By the time, Directory.Delete is called, folder is empty. When I called this, directory is not deleted but the exception is also not raised. I can see the folder. If we try to access the folder, I am getting Access Denied error. At this time, if I restart the machine, then I dont see the folder again after the restart. Is this something like, windows is taking care while doing the restart or Directory.Delete is taking some time to delete the folder? Before deleting the folder, files in the folder was used by our own service. If there is any access issue, it should have raised the exception and it should not have deleted the files. Please check sample code below. 

     try
    -            {
    -                var allFiles = Directory.GetFiles(installationWorkingDirectory, "*");
    -                if (allFiles.Length > 0)
    -                {
    -                    
    -                foreach (var file in allFiles)
    -                {
    -                    File.Delete(file);
    -                }
    -            }
    -            catch (Exception ex)
    -            {
    -                result = new ResultObject<DeleteDirectoryResult>(ex, DeleteDirectoryResult.ErrorOnDeleteFiles);
    -
    -                return result;
    -            }
    -
    -            try
    -            {
    -                Directory.Delete(installationWorkingDirectory, true);
    -            }
    -            catch (Exception ex)
    -            {
    -                result = new ResultObject<DeleteDirectoryResult>(ex, DeleteDirectoryResult.ErrorOnDeleteDirectory);
    -            }

    Regards

    Nagaraju

    Sunday, February 18, 2018 5:44 PM

All replies