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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:55:39+00:00 2026-05-11T16:55:39+00:00

I have a job that runs every night to pull xml files from a

  • 0

I have a job that runs every night to pull xml files from a directory that has over 20,000 subfolders under the root. Here is what the structure looks like:

rootFolder/someFolder/someSubFolder/xml/myFile.xml
rootFolder/someFolder/someSubFolder1/xml/myFile1.xml
rootFolder/someFolder/someSubFolderN/xml/myFile2.xml
rootFolder/someFolder1
rootFolder/someFolderN

So looking at the above, the structure is always the same – a root folder, then two subfolders, then an xml directory, and then the xml file.
Only the name of the rootFolder and the xml directory are known to me.

The code below traverses through all the directories and is extremely slow. Any recommendations on how I can optimize the search especially if the directory structure is known?

string[] files = Directory.GetFiles(@"\\somenetworkpath\rootFolder", "*.xml", SearchOption.AllDirectories);
  • 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-11T16:55:39+00:00Added an answer on May 11, 2026 at 4:55 pm

    Rather than doing GetFiles and doing a brute force search you could most likely use GetDirectories, first to get a list of the “First sub folder”, loop through those directories, then repeat the process for the sub folder, looping through them, lastly look for the xml folder, and finally searching for .xml files.

    Now, as for performance the speed of this will vary, but searching for directories first, THEN getting to files should help a lot!

    Update

    Ok, I did a quick bit of testing and you can actually optimize it much further than I thought.

    The following code snippet will search a directory structure and find ALL “xml” folders inside the entire directory tree.

    string startPath = @"C:\Testing\Testing\bin\Debug";
    string[] oDirectories = Directory.GetDirectories(startPath, "xml", SearchOption.AllDirectories);
    Console.WriteLine(oDirectories.Length.ToString());
    foreach (string oCurrent in oDirectories)
        Console.WriteLine(oCurrent);
    Console.ReadLine();
    

    If you drop that into a test console app you will see it output the results.

    Now, once you have this, just look in each of the found directories for you .xml files.

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

Sidebar

Related Questions

I have an automated job that pulls files that are uploaded to our servers
I have a nightly batch job that can tell if it has failed. I
I have a C#/.Net job that imports data from Excel and then processes it.
URL for reference: jobs.sitesixteen I currently have a query that runs every time a
I have a AsyncTask that runs and does its job and completes. onPostExecute does
I'm a c# developer but have a job that involves some jsp code. I've
Here's my scenario - I have an SSIS job that depends on another prior
I have a cron job on an Ubuntu Hardy VPS that only half works
At my current job we have a CMS system that is .NET/SQL Server based.
I have an application that uses a cron like job to update a set

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.