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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:58:30+00:00 2026-05-25T20:58:30+00:00

I am trying to retrieve list of files from a server with the windows

  • 0

I am trying to retrieve list of files from a server with the windows command – “DIR /S/B”
The output is huge (around 400 MB). Now when I tried retrieve it with below approach, its taking hours to process. Is there any faster way to do it.

string path = args[0];
var start = DateTime.Now;

System.Diagnostics.ProcessStartInfo procStartInfo =
    new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "dir /s/b " + path );
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();

//string [] result = proc.StandardOutput.ReadToEnd().Split('\n'); ;

StreamWriter writer = new StreamWriter("FileList.lst");
while (proc.StandardOutput.EndOfStream != true)
{
    writer.WriteLine(proc.StandardOutput.ReadLine());
    writer.Flush();
}
writer.Close();
  • 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-25T20:58:31+00:00Added an answer on May 25, 2026 at 8:58 pm

    Why not use DirectoryInfo.GetFiles?

    I’m guessing quite a bit of your time now is being eaten up by the command executing, not the .NET code. It’ll take dir a long time to write that much data to a stream in sequence. You then use String.Split which is also going to choke on that much data.

    By using DirectoryInfo.GetFiles, you should be able to get all the file names in a single line (and you could also get other information about the files this way):

    var files = (new DirectoryInfo(path)
                    .GetFiles("*.*", SearchOption.AllDirectories)
                    .Select(fi => fi.Name);
    

    If you’re really only concerned about filenames, you could use:

    var fileNames = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve a list of *.zip files from server B which is
I'm trying to retrieve image file from my local server. Here is my (very
I've been trying to set up a ftp server using IIS from windows 7.
I'm trying to retrieve a list of documents from a folder named myfolder in
Very new mobile developer here... I am trying to retrieve a list of tweets
I am trying to figure out a query to retrieve list of categories that
In my block code I am trying to programmatically retrieve a list of products
I'm trying to retrieve odd values in a List of strings and convert them
I am currently trying to build a little widget that will retrieve a list
I'm trying to generate a list dynamically from database. The results can be retrieved,

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.