Hello,
I have written a C# console application that currently takes a data file as input, processes the data and writes out 2 new data files. I would like for it to be able to process ALL the files in a given directory. How might I do this? Thanks!

You can get a list of files in a directory by using the function Directory.GetFiles();

Here is an example that reads all the data from each file and stores it in the variable 'data'.

string directory = @"C:\";
foreach (string file in Directory.GetFiles(directory))
{
    string data = "";
    using (StreamReader sr = new StreamReader(file))
    {
        data = sr.ReadToEnd();
    }

    // Do something with the data from each file found
}

Thanks guys. That is exactly what I was looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.