Hello Guys, My job is to process the text files. following are the steps that i have to do.
1: To combine multiple text files into one text file
2: Add filename (but without extension) in the beginning of each text file.
3: and Finally, index the contents of the file by 1,2,3 i.e., if the contents of the text file are 378456 354789 564876
then index it with 1:378456 2:354789 3:564876 4:56879 ......so on
I have written the following code, which is combining the multiple text files into one file and also adds the file name without extension...but i am not able to index its contents. Please help me out....
Regards
static void Main(string[] args)
{
string[] files = Directory.GetFiles(@"F:\kkj\", "*.txt", SearchOption.AllDirectories);
StringBuilder strFile = new StringBuilder();
foreach (string file in files)
{
using (StreamReader sr = new StreamReader(file))
{
string s = Path.ChangeExtension(file, null);
strFile.AppendFormat(s.Substring(s.LastIndexOf(@"\") + 1) + " ");
strFile.Append(sr.ReadToEnd());
}
}
using (StreamWriter outfile = new StreamWriter(@"F:\kkj\" + @"\FinalOutputFile.txt"))
{
outfile.Write(strFile.ToString());
}
}