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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:44:49+00:00 2026-05-14T03:44:49+00:00

Every example I see seems to be for recursively getting files in subdirectories uses

  • 0

Every example I see seems to be for recursively getting files in subdirectories uses files only. What I’m trying to do is search a folder for a particular subdirectory named “xxx” then save that path to a variable so I can use it for other things.

Is this possible without looping through all the directories and comparing by name?

  • 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-14T03:44:49+00:00Added an answer on May 14, 2026 at 3:44 am

    Well

    Directory.GetDirectories(root);
    

    will return you an array of the subdirectories.

    You can then use Linq to find the one you’re interested in:

    IEnumerable<string> list = Directory.GetDirectories(root).Where(s => s.Equals("test"));
    

    which isn’t a loop in your code, but is still a loop nevertheless. So the ultimate answer is that "no you can’t find a folder ‘test’ without looping".

    You could add .SingleOrDefault() to the Linq, but that would depend on what you wanted to do if your "test" folder couldn’t be found.

    If you change the GetDirectories call to include the SearchOption SearchOption.AllDirectories then it will do the recursion for you as well. This version supports searching – you have to supply a search string – though in .NET Framework it’s case sensitive searching. To return all sub directories you pass "*" as the search term.

    Obviously in this case the call could return more than one item if there was more than one folder named "test" in your directory tree.

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

Sidebar

Related Questions

Every example I can find is in C++, but I'm trying to keep my
I was reading Enumerations in Java, and every example I have come across uses
For typical examples I see of SqlDataSource, LinqDataSource... EVERY example deal with how to
As far as I see every time I make a change, for example the
Every now and then I see these being used, but it never seems to
In my application I store on every machine some files in an application folder.
It seems like every example I can find has to do with using DirectX
Every example I've seen of CGI/Perl basically a bunch of print statements containing HTML,
Every example I've seen on the web, e.g. http://www.codeproject.com/KB/docview/jms_to_jms_bridge_activem.aspx , creates a publisher and
I have searched and tried every example regarding singleton, public, and global variables in

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.