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 8249729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:38:41+00:00 2026-06-07T23:38:41+00:00

The issue is System.UnauthorizedAccessException on recycle bin or documents and settings folders/files. (VS2010 .NET

  • 0

The issue is System.UnauthorizedAccessException on recycle bin or documents and settings folders/files. (VS2010 .NET 4.0 C#)

The following LINQ code to query directory sizes. I have tried GetFiles and EnumerateFiles. I am definitely running as admin. In the commented code you can see I tried testing for some attributes from another Stack post without success.

DirectorySize(new DirectoryInfo(@"C:\\"),true);

public static long DirectorySize(DirectoryInfo dInfo, bool includeSubDir)
{
    // Enumerate all the files
    long totalSize = dInfo.EnumerateFiles().Sum(file => file.Length);
        //.Where(d => (d.Attributes & FileAttributes.ReparsePoint) == 0 && (d.Attributes & FileAttributes.System) == 0)
        //.Sum(file => file.Length);

    if (includeSubDir) // Subdirs?
    {
        // Enumerate all sub-directories
        totalSize += dInfo.EnumerateDirectories().Sum(dir => DirectorySize(dir, true));
            //.Where(d => (d.Attributes & FileAttributes.ReparsePoint) == 0 && (d.Attributes & FileAttributes.System) == 0)
            //.Sum(dir => DirectorySize(dir, true));
    }
    return totalSize;
}

I would like to get a concise LINQ method where I don’t have to manually loop and test every folder/dir. I found some MS code for duplicates that operates similarly. It errors out the same too.

My thanks in advance,

  • 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-07T23:38:42+00:00Added an answer on June 7, 2026 at 11:38 pm

    try/catch to the rescue as demonstrated in the following article. There are also alternatives.

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

Sidebar

Related Questions

I'm trying to track down an issue in our system and the following code
Some code to replicate the issue: using System; public abstract class Response { }
I have the following code in a VB .NET application. I am trying to
What is the issue tracking system used by Google Code to track projects like
I'm working on a basic Issue Management System in order to learn ASP.NET MVC.
I have an issue with System.Threading.Timer. I am scheduling some actions using a time
I am working on an issue management system, developed in PHP/MySQL. It requires search
In a system I'm building, it's essentially an issue tracking system, but with various
Here's my problem: there's an internal issue tracking system that has a nice summary
While debugging an issue with our system, I have discovered a thread contention 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.