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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:31:07+00:00 2026-06-04T05:31:07+00:00

I am writing a software tool which, as part of its main task, must

  • 0

I am writing a software tool which, as part of its main task, must search a directory and its sub directories for a directory with a given name, and save to a string array each file path that terminates with the specified directory name. For example:

                   level_1      level_2      Level_3
RootDirectory ---> folderA ---> folderD ---> FolderF ---> Target
             |            |---> folderE ---> Target
             |            
             |---> folderB ---> Target
             |
             |---> FolderC ---> Target

should pump out:

string[] = {RootDirectory\folderA\FolderD\folderF\Target,  
    RootDirectory\folderA\folderE\Target, 
    Rootdirectory\folderB\Target, 
    RootDirectory\foderC\Target}

Originally I used getDirectories(myPath, "Target", SearchOption.AllDirectories) on a directory info object, but there was an issue. For some reason, it would find the target under folders b and c, and also under folderA>folderD>folderF, but would skip FolderE. Once it found the first occurrence within the sub directory, folderA, it would go on to the next folder at level_1. I should mention that folderD in my real-case was in fact alphabetically sorted before folderE, as it is in this example

so instead I decided to use an IEnumerator and run a where filter to select the files that terminate with the given directory name. This found them all. However, i cannot figure out how to do something like getDirectories().Where(x=>(x.attributes & fileattributes.hidden)==0); on an IEnumerator.

The problem is, I need it to skip hidden SVN directories because it is slowing down the process considerably.

So here is my question:
how can I get a collection of all paths within a sub directory that end in a given directory name, and exclude hidden files form the search?

  • 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-04T05:31:08+00:00Added an answer on June 4, 2026 at 5:31 am

    I think you’re going to have to write your own implementation. If you are in .net 4.0, you could use EnumerateDirectories

    and do something like this:

    private IEnumerable<DirectoryInfo> EnumerateDirectories(DirectoryInfo dir, string target)
    {
        foreach (var di in dir.EnumerateDirectories("*",SearchOption.TopDirectoryOnly))
        {
            if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
            {
                if (di.Name.EndsWith(target, StringComparison.OrdinalIgnoreCase))
                {
                     yield return di;
                     continue;
                }
                foreach (var subDir in EnumerateDirectories(di, target))
                {
                    yield return subDir;
                }
            }
        }
    }
    

    Then:

    DirectoryInfo dir = new DirectoryInfo(@"C:\RootDirectory");
    var found = EnumerateDirectories(dir,"target").ToArray();
    

    This way, once you either find a “target”, or run into a hidden directory, you stop going through sub directories.

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

Sidebar

Related Questions

I am writing a simple software protection tool which works by reading the input
I'm writing my first proper useful piece of software. Part of it will involve
For a new project, I'm writing an administrative tool as a client software. So
I am writing a tool that monitors a network directory and is running off
I'm writing software in VB .NET (2005) which uses the Windows user information as
I am writing a software which stores all the information of a users interaction
I'm writing some software in which I need to compute bivariate densities of an
I am writing a software which sells certain service to it's user. I am
I'm writing software for a new hardware device which I want any kind of
I am writing a software using Qt. One of my task is to judge

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.