get the list of text files and process each file as below
string[] files =
Directory.GetFiles(@"E:\1150\1150\","*.txt", SearchOption.AllDirectories);
foreach(string file in files )
{
using(StreamReader streamReader = new StreamReader(file))
{
string text = streamReader.ReadToEnd();
}
}
Quote:
we have create one test.csv file in that test file we have 2 rows
1. folderName and
2. nameofFile
string[] files contains array of
File Paths (both directory and filename is in the string), read
Path.GetFileName Method[
^] and
Path.GetDirectoryName Method[
^] which will help you to get filename and Directory form path string.
Now We came to Final Task;
writing csv is simple, for example
using(var w = new StreamWriter(path))
{
foreach(string filepath in files )
{
var directory= Path.GetDirectoryName(file);
var fileName= Path.GetFileName(file);
var line = string.Format("{0},{1}", directory, fileName);
w.WriteLine(line);
w.Flush();
}
}
hope this helps you