Merge text Files

I want to create a small program....basically upgrade a .bat program to program.

merge.bat code
copy clf*.* clf_all.txt
copy data*.* tpdta.txt
copy head*.* tphed.txt
copy pmnt*.* tppay.txt
copy text*.* tptxt.txt
copy sl*.* sl.txt
copy po*.* po.txt

Now i want to create an interface where user can select multiple text and merge them like the above merge.bat program.

Can some1 help me out. I know its a really simple program but i have not done any windows coding.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

RyanAndresConnect With a Mentor Commented:

Private Shared Sub Main(ByVal args As String())
    Dim filenames As String() = New String(2) {}
    filenames(0) = "file1.txt"
    filenames(1) = "file2.txt"
    filenames(2) = "file3.txt"
    Dim stream As New FileStream("output.txt", FileMode.OpenOrCreate, FileAccess.Write)
    For Each file As String In filenames
        Dim data As Byte() = GetDataFromFile(file)
        stream.Write(data, 0, data.Length)
End Sub

Private Shared Function GetDataFromFile(ByVal filename As String) As Byte()
    Dim stream As New FileStream(filename, FileMode.Open)
    Dim buffer As Byte() = New Byte(stream.Length - 1) {}
    stream.Read(buffer, 0, CInt(stream.Length))
    Return buffer
End Function
RyanAndresConnect With a Mentor Commented:
Of course you want to include file exist checks and catch other necessary exceptions.

The code above was converted from C# using a web resource. Below is the C# code.
static void Main(string[] args)
    string[] filenames = new string[3];
    filenames[0] = "file1.txt";
    filenames[1] = "file2.txt";
    filenames[2] = "file3.txt";
    FileStream stream = new FileStream("output.txt",
        FileMode.OpenOrCreate, FileAccess.Write);
    foreach (string file in filenames)
        byte[] data = GetDataFromFile(file);
        stream.Write(data, 0, data.Length);
private static byte[] GetDataFromFile(string filename)
    FileStream stream = new FileStream(filename, FileMode.Open);
    byte[] buffer = new byte[stream.Length];
    stream.Read(buffer, 0, (int)stream.Length);
    return buffer;

Open in new window

I want to merge files not to join them. I mean i have file1 and file2 which has to be merged not join
Merging requires logic. How will they merge? Could you use something like winmerge?
All Courses

From novice to tech pro — start learning today.