C#. Join (merge) some text files into one




The task. We have 3 separated text files, for example, web server logs. For more comfortable analyze we want to join them into one file. Below my simple solution for this task in C#.

The main steps of script are:

  1. Read directory and get filenames. Add names to array of string
  2. Loop through array of filenames, read contents of files and add it to string collection List<string> stringList
  3. Join string collection List<string> to a string variable
  4. Write result to textFile

 

Full code of console application below. It's the simple version. You may add more features to a code if you want to.

joinedFiles



No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment





MarkiMarta.com. Notes of web-specialist
Since 2009
18+
Code examples: Get date minus 1 day

Source: A date in string format, for example, "2015-04-21". The task: To find a date minus 1 day from the source. Solution:

Close