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

  • Home
  • SEARCH
  • 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 7940005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:15:26+00:00 2026-06-03T23:15:26+00:00

Question: Why do I get this error while scanning a users ‘My Documents’ folder,

  • 0
  1. Question: Why do I get this error while scanning a users ‘My Documents’ folder, but not when I scan the ‘My Music/My Pictures/My Videos’ directory?
  2. Secondary, less important question: Is there a way to avoid this without having to specifically filter these folders out, or using a try/catch block?

I prefer answers that teach me how to fish, instead of just giving me fish. Just at this point I am not sure where I need to look to specifically answer this question. I’ve read through documents about elevating permissions and iterating through the file system, and spent a good week looking for why I can set DirectoryInfo on ‘User\My Music’ but not ‘User\Documents\My Music'(link) and just would enjoy a little boost in a different direction in regards to learning more.

I catch the initial ‘UnauthorizedAccessException’ that is thrown initially when attempting Directory.GetFiles(‘path’, “*”, SearchOption.AllDirectories) where path is the users ‘My Documents’. To handle the exception I know that I need to walk the directory manually. Which works, returning the files from the sub-directories.

The code for the initial GetFiles function:

public static string[] GetFiles(string path)
{
    string[] files;
    try
    {
        files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
    }
    catch(UnauthorizedAccessException ex)
    { files = WalkDirectory(path); }
    return files;
}

public static string[] WalkDirectory(string path)
{
    List<string> files = new List<string>();
    DirectoryInfo dir = new DirectoryInfo(path);

    foreach (DirectoryInfo subDir in dir.GetDirectories())
    {
        try
        {
            files.AddRange(WalkDirectory(subDir.FullName));
        }
        catch(UnauthorizedAccessException ex)
        {
            // complete fail to walk directory listed
            throw ex;
        }
    }
    foreach (FileInfo file in dir.GetFiles())
    {
        files.Add(file.FullName);
    }
}

This works out perfectly, until the code attempts to walk the hidden folders: My Music, My Pictures, or My Videos. No matter how I try and re-code to walk the hidden files, I keep receiving the UnauthorizedAccessException.

I understand completely that I am going to code around this. Mainly what I am curious to know, is why is the exception happening under a users folder?

An asssumption I am making is that the folder is a symlink to another directory, because I can make the path ?:\users directory\user\My (Music, Pictures, or Videos) and the code walks those directories then without any issues. This only happens when trying to scan the directory files after setting them from within the users My Documents.

  • OS: Windows 7
  • User Privliages: Administrator
  • Application Elevated to run as administrator
  • 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-03T23:15:28+00:00Added an answer on June 3, 2026 at 11:15 pm

    I was speaking about this with a friend, who is not technical, but knows enough tech to hold a conversation and he helped me narrow this question down further. This is actually a duplicate question and was answered at Check if a file is real or a symbolic link.

    The folder is a symbolic link that was placed there for backwards compatibility purposes according to this article on TechRepublic: Answers to some common questions about symbolic links under the section Windows Vista and Windows 7 have built-in symbolic links paragraph 2.

    In order to specifically avoid attempting to scan this directory without a Try/Catch block on an UnauthorizedAccessException the folder attributes need to be checked to determine if the folder or file in question is a symbolic link. Which again was answered in the above listed stackoverflow question.

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

Sidebar

Related Questions

Hello I asked this question to superuser but I did not get a good
I am using the code as described in this question. However get following error
This is actually a non-critical question, but I get this warning most of the
Pretty much the same as this question. But I can't seem to get this
Hopefully the last NN question you'll get from me this weekend, but here goes
I have asked this before but I didn't get the question right so the
I posted this question on Reddit Programming and did not get a single response.
I get this error message while compiling: Assembly 'MyFramework [...]' uses 'System.Web.Extensions, Version=3.5.0.0 [...]'
When submitting an answer I get this error: ActiveRecord::RecordNotFound (Couldn't find Question with ID=answer):
I have a route defined like this: GET /question/:q_id controllers.Questions.viewQuestion(q_id: Long) Then in my

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.