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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:52:40+00:00 2026-05-27T11:52:40+00:00

I am currently developing a C# application to search a file in the computer.

  • 0

I am currently developing a C# application to search a file in the computer. The GUI has two text fields: one for input(the name for the file to be searched) and one for displaying the path to the file (if it’s found).

Now, the problem is that my application is skipping my logical C: drive. Here is some piece of code:

foreach (string s in Directory.GetLogicalDrives() )
{
    if (list.Count == 0)
    {
        foreach (string f in Directory.GetFiles(s, file))
        {
            textBox2.Text = f;
            list.Add(f);
        }
        if (list.Count == 0)
        {
            search(s);
        }
    }
}

And the search method:

private void search(string sDir)
{
    try
    {
        foreach (string d in Directory.GetDirectories(sDir))
        {
            if (list.Count == 0)
            {
                Console.WriteLine(d);
                foreach (string f in Directory.GetFiles(d, file))
                {
                    textBox2.Text = f;
                    list.Add(f);
                }
                if (list.Count == 0)
                {
                    search(d);
                }
            }
        }
    }
    catch (System.Exception excpt)
    {
        Console.WriteLine(excpt.Message);
    }
}

Here is some output:

C:\$Recycle.Bin
C:\$Recycle.Bin\S-1-5-21-1794489696-3002174507-1726058468-1000
C:\Config.Msi
C:\de cautat
C:\de cautat\database
C:\de cautat\fut_bot
C:\de cautat\helper
C:\de cautat\images
C:\de cautat\itemiinfo
C:\de cautat\JSONs
C:\de cautat\JSONs\PLAYER
C:\de cautat\JSONs\USER
C:\de cautat\requests
C:\Documents and Settings
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Access to the path 'C:\Documents and Settings' is denied.
D:\$RECYCLE.BIN
D:\$RECYCLE.BIN\S-1-5-21-1794489696-3002174507-1726058468-1000
D:\$RECYCLE.BIN\S-1-5-21-2637989945-465084399-3498881169-1000
etc

Can anyone help me and tell what is the problem when accesing those folders? Thanks!

Note: I am using Microsoft Visual Studio 2010 on Windows 7 x64 (.NET Framework 2.0).

  • 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-27T11:52:41+00:00Added an answer on May 27, 2026 at 11:52 am

    Move your try catch into the foreach (string d in Directory.GetDirectories(sDir)) loop so it continues to process on error.

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

Sidebar

Related Questions

I am currently developing an application, which gets the input from a text file
I'm currently developing an application that happens to require some file preprocessing before actually
Currently i am developing an application whose name is long , so i would
I'm currently developing an application that needs to parse some (a big file of)
I am currently developing an application with the intention of only using chrome, one
I'm am currently developing an ASP.NET intranet application. One of the features of this
I am currently developing an application which has a maps feature. My map is
I am currently developing a an application to allow users to search through a
Currently developing an application using the newest version of symfony, obtained through PEAR. This
I'm currently developing an application that is comprised of five separate executables that communicate

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.