Solved

Open Files in a folder

Posted on 2003-12-12
1
507 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now