Solved

Open Files in a folder

Posted on 2003-12-12
1
511 Views
Last Modified: 2012-05-04
How can I just have a program consecutively open each file in a specified folder in order? I don't want to have to select them (because the puts a limit to around 400 or so). I just need it to take a folder and load each file one after another.
0
Comment
Question by:derekthornton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
TransBind earned 500 total points
ID: 9928876
This worked for me.  I'm just printing the output but you can replace the Response.Write line with any type of array or ArrayList, etc.

private void Page_Load(object sender, System.EventArgs e)
{
  DirectoryInfo dir = new DirectoryInfo("D:\\EfficiencyLab\\");
      TraverseFolder(dir);              
}

    private void TraverseFolder(DirectoryInfo dir)
    {
      FileInfo[] filesInDir = dir.GetFiles();
      foreach(FileInfo file in filesInDir)
      {
        Response.Write(file.Name + "<br>");        
      }
      DirectoryInfo[] directories = dir.GetDirectories();
      foreach(DirectoryInfo newDir in directories)
      {
        TraverseFolder(newDir);
      }

This is also a recursive function.  I tried it out and it's fast.  Just don't try to access any restricted directories.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question