?
Solved

Open Files in a folder

Posted on 2003-12-12
1
Medium Priority
?
513 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 2000 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

Technology Partners: 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 Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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