Hack Forums
[.NET] Simple Text File Merger + Source - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Simple Text File Merger + Source (/showthread.php?tid=4671283)



Simple Text File Merger + Source - jkrules420 - Feb 5, 2015

Here is a simple too I made, It simply allows you to select a folder with multiple .txt or .xml files and merge them into a single .txt or .xml file.

Screenshot:
[Image: 4gdsLbS.png]

Code
Public Class TextFileMerger
    Dim X, Y As Integer
    Dim NewPoint As New System.Drawing.Point

#Region "Move Panel"
    Private Sub Panel1_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
      X = Control.MousePosition.X - Me.Location.X
      Y = Control.MousePosition.Y - Me.Location.Y
    End Sub
    Private Sub Panel1_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
      If e.Button = Windows.Forms.MouseButtons.Left Then
      NewPoint = Control.MousePosition
      NewPoint.X -= (X)
      NewPoint.Y -= (Y)
      Me.Location = NewPoint
      End If
    End Sub
    Private Sub Label1_MouseDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown
      X = Control.MousePosition.X - Me.Location.X
      Y = Control.MousePosition.Y - Me.Location.Y
    End Sub
    Private Sub Label1_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseMove
      If e.Button = Windows.Forms.MouseButtons.Left Then
      NewPoint = Control.MousePosition
      NewPoint.X -= (X)
      NewPoint.Y -= (Y)
      Me.Location = NewPoint
      End If
    End Sub
#End Region

#Region "Buttons"
    Private Sub MinimizeB_Click(sender As Object, e As EventArgs) Handles MinimizeB.Click
      Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
    End Sub
    Private Sub CloseB_Click(sender As Object, e As EventArgs) Handles CloseB.Click
      Me.Close()
    End Sub
    Private Sub OpenB_Click(sender As Object, e As EventArgs) Handles OpenB.Click
      SelectFolder()
    End Sub
    Private Sub MergeB_Click(sender As Object, e As EventArgs) Handles MergeB.Click
      FormatCheck()
    End Sub
#End Region

#Region "Work"
    Sub SelectFolder()
      Using FD As New FolderBrowserDialog
      If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
            FolderDirT.Text = (FD.SelectedPath.ToString)
            StatusT.Text = (FD.SelectedPath.ToString + " Selected!")
      End If
      End Using
    End Sub
    Sub FormatCheck()
      If RadioButton1.Checked = True Then
      StatusT.Text = "Format = Text"
      Txtmerge()
      ElseIf RadioButton2.Checked = True Then
      StatusT.Text = "Format = XML"
      Xmlmerge()
      Else
      MessageBox.Show("Please Select a format to continue.")
      StatusT.Text = "No Format Selected!"
      End If
    End Sub
    Sub Txtmerge()
      Dim myprocess As New Process
      Dim StartInfo As New System.Diagnostics.ProcessStartInfo
      StartInfo.FileName = "cmd"
      StartInfo.RedirectStandardInput = True
      StartInfo.RedirectStandardOutput = True
      StartInfo.UseShellExecute = False
      myprocess.StartInfo = StartInfo
      myprocess.Start()
      Dim SR As System.IO.StreamReader = myprocess.StandardOutput
      Dim SW As System.IO.StreamWriter = myprocess.StandardInput
      SW.WriteLine("copy *.txt " + TextBox2.Text + ".txt")
      StatusT.Text = SR.ReadToEnd
      StatusT.Text = SR.ReadToEnd
      SW.WriteLine("exit")
      SW.Close()
      SR.Close()
      StatusT.Text = "Merging txt Files Finished!"
      MessageBox.Show("Finished! All Files Merged Into " + FolderDirT.Text + "\" + TextBox2.Text + ".txt")
    End Sub
    Sub Xmlmerge()
      Dim myprocess As New Process
      Dim StartInfo As New System.Diagnostics.ProcessStartInfo
      StartInfo.FileName = "cmd"
      StartInfo.RedirectStandardInput = True
      StartInfo.RedirectStandardOutput = True
      StartInfo.UseShellExecute = False
      myprocess.StartInfo = StartInfo
      myprocess.Start()
      Dim SR As System.IO.StreamReader = myprocess.StandardOutput
      Dim SW As System.IO.StreamWriter = myprocess.StandardInput
      SW.WriteLine("copy *.xml " + TextBox2.Text + ".xml")
      StatusT.Text = SR.ReadToEnd
      StatusT.Text = SR.ReadToEnd
      SW.WriteLine("exit")
      SW.Close()
      SR.Close()
      StatusT.Text = "Merging XML Files Finished!"
      MessageBox.Show("Finished! All Files Merged Into " + FolderDirT.Text + "\" + TextBox2.Text + ".xml")
    End Sub
#End Region
End Class

Source Code DL: http://www.mediafire.com/download/c5x5xesdsc25z8g/TextFileMerger.zip
https://www.virustotal.com/en/file/c299704aa4d30f30e14d02766500b7a41f5b132bca4cf2aea0fa6e81a042f842/analysis/1423126733/
.exe DL: http://www.mediafire.com/download/0ufh12ufpz2jf6a/Text+File+Merger.exe


* - Odus - Feb 5, 2015

Why is CMD getting involved? Pretty much all of this can be condensed:

Code
If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim di As New DirectoryInfo(fbd.SelectedPath)
    File.WriteAllLines(Path.Combine(fbd.SelectedPath, "merged.txt"), di.GetFiles().SelectMany(Function(f) File.ReadAllLines(f.FullName)))
End If



* - jkrules420 - Feb 5, 2015

(Feb 5, 2015 10:33 AM)Odus Wrote:  Why is CMD getting involved? Pretty much all of this can be condensed:

Code
If fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
    Dim di As New DirectoryInfo(fbd.SelectedPath)
    File.WriteAllLines(Path.Combine(fbd.SelectedPath, "merged.txt"), di.GetFiles().SelectMany(Function(f) File.ReadAllLines(f.FullName)))
End If

I see that, I will update the program using that idea, I just had a use for this program and only knew how to do it in CMD that is why I did it like that


* - CryptGetUserKey - Feb 5, 2015

Here. Learn a few things.
Code
while(entry)
{
memcpy(buf,entry->data,entry->size);
entry += entry->nextOffset;
buf+=entry->size;
}
👹