I am currently building a transcompiler for batch and I want an option where you can edit existing batch files through a Rich Textbox in VB.Net How does one do this? It is known knowledge that you can edit batch files through notepad without even touching the file type.
Use a StreamReader
to load the text into the RichTextBox
. For example:
Dim StreamReader1 As New IO.StreamReader
RichTextBox1.Text = StreamReader1.ReadToEnd()
You may also want to use an OpenFileDialog
to load the file. Add a OpenFileDialog
to your Form
first.
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.FileName = "Open a Batch File"
OpenFileDialog1.Filter = "Batch files (*.bat) | *.bat"
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
Dim StreamReader1 As New IO.StreamReader(OpenFileDialog1.FileName)
RichTextBox1.Text = StreamReader1.ReadToEnd
StreamReader1.Close()
Else
'What to do if OpenFileDialog is cancelled
End If