tags:

views:

13

answers:

1

Hi,

I have a parser function written in my code-behind file, that takes as input the filename of a csv file, and parses the data accordingly. In the current scenario, I am supplying the name of the csv file.

In a newer scenario, I would like to scan a particular local directory for csv files, and pass all of them to the parser function one by one.

My current function looks like this:

public List<string[]> parseCSVFile(string path)
{
  ...
}

and I'm calling it like this:

List<string[]> Data = parseCSVFile("C:\\Users\\joysteak\\Documents\\Visual Studio 2008\\WebSites\\Ingy\\data\\results2010.csv");

Any help is much appreciated :)

+1  A: 

I think this is what you're looking for:

string[] csvFiles = Directory.GetFiles("C:\\somedirectory", "*.csv");

foreach(string file in csvFiles)
{
   List<string[]> Data = parseCSVFle(file);
}

Keep in mind, if you're doing this in ASP.NET, the work process identity (usually NETWORK SERVICE) will need at least read permissions to the folder you're wanting to search if it's outside the web's root path.

Coding Gorilla
Thank you, this is exactly what I was looking for :)
Freakishly