Click here to Skip to main content
12,349,169 members (68,784 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

13.9K views
2 bookmarked
Posted

Merge Multiple text files in a folder

, 28 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
How to merge all text files in a folder
This article will show you how to merge the text of text files located in a directory.
string[] txtFiles;
txtFiles = Directory.GetFiles(txtFileDestination.Text, "*.txt");
using (StreamWriter writer = new StreamWriter(txtFileDestination.Text + @"\allfiles.txt"))
{
    for (int i = 0; i < txtFiles.Length; i++)
    {
        using (StreamReader reader = File.OpenText(txtFiles[i]))
        {
              writer.Write(reader.ReadToEnd());
        }
    }
}

[Modified: it really doesn't take much to fix the tabbing...]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Manish Choudhary .NET expert
Software Developer Cybosoft Technologies
Australia Australia
I am working as a Team Leader in HimanshuSofttech(http://www.himanshusofttech.com) a new born Search Engine Optimization and software developement Company Located in Dewas, A Holy place of India. I started my programing life as a VB.NET Developer but now I am working in C#.NET.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 28 Jan 2011
Article Copyright 2011 by Manish Choudhary .NET expert
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid