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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:43:26+00:00 2026-05-25T14:43:26+00:00

Currently I have a program that searches a user set directory and sub-directories for

  • 0

Currently I have a program that searches a user set directory and sub-directories for music files and adds them to a collection. However if one of the directories it comes accross is protected then the program falls over. I wanted to know how I can check if the user has access to the directory before trying to search it to avoid this problem.
Below is the code I’m using for the search, it currently contains a basic work around for “System Volume Information” but as there is a possibility that there may be other protected directories I wanted to change this to include them.

    public void SearchForMusic()
    {
        //Searches selected directory and its sub directories for music files and adds their path to ObservableCollection<string> MusicFound
        foreach (string ext in extentions)
        {
            foreach (string song in Directory.GetFiles(SearchDirectory, ext))
            {
                musicFound.Add(song);                   
            }

            foreach (string directory in Directory.GetDirectories(SearchDirectory))
            {
                if (directory.Contains("System Volume Information"))
                {

                }
                else
                {
                    foreach (string song in Directory.GetFiles(directory, ext))
                    {
                    musicFound.Add(song);
                    }

                    foreach (string subDirectory in Directory.GetDirectories(directory))
                    {
                        foreach (string subSong in Directory.GetFiles(subDirectory, ext))
                        {
                            musicFound.Add(subSong);
                        }
                    }
                }
            }
        }
    }

Many thanks 🙂

  • 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-05-25T14:43:27+00:00Added an answer on May 25, 2026 at 2:43 pm

    By far the easiest way to be sure that you have access to a file system object is to attempt to access it. If it fails with an Access Denied error, then you don’t have access. Just detect that error condition and proceed with the next item in the search.

    In other words, delegate checking access to the system which is, after all, the ultimate arbiter of access rights.

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

Sidebar

Related Questions

We have an app that currently installs itself into 'program files\our app', and it
I currently have a program that finds and edits HTML files based on finding
I am writing a program that searches and copies mp3-files to a specified directory.
Currently I have a program that takes as input a folder that contains .MPP
I have a Ruby program that loads up two very large yaml files, so
Currently, I have a program that reads a file and uses an XMLTextWriter to
I have a program that searches a file (numbers.dat) using a binary search and
Historically operating system directory-structures have been trees: C: Windows System32 Program Files Common Files
I currently have a program that runs several intense queries. I added a textbox
I currently have a program that i wrote that is divided up into 3

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.