我正在尝试创建一个简单的程序,它将多个文本文件合并为一个。基本上,它们是升级脚本。因此,有一个“从”升级组合框和一个“升级到”组合框。到目前为止,我已经设法让程序读取目录,以查看目录中存在哪些版本脚本,并按升序对其进行排序。
我遇到的麻烦是将多个文件组合在一起。我已经设法对其进行编码,因此将两个脚本合并为一个,但已对其进行了硬编码。我希望程序选择正确的脚本而不对其进行硬编码。有人可以帮忙吗?
此代码很好,它可以根据目录中列出的文件填充组合框并按升序对其进行排序:
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim counter As Integer
Dim scriptcount As Integer
counter = 0
scriptcount = 0
For Each file As String In System.IO.Directory.GetFiles(dir)
counter = counter + 1
version(counter) = System.IO.Path.GetFileNameWithoutExtension(file)
versionfilepath(counter) = "C:\itcd\" + System.IO.Path.GetFileName(file)
Next
scriptcount = counter
Do While counter >= 1
cmbFrom.Items.Add(version(counter))
cmbTo.Items.Add(version(counter))
counter = counter - 1
Loop
End Sub
这部分我需要帮助。
Private Sub butGenerate_Click(sender As Object, e As EventArgs) Handles butGenerate.Click
Dim counter As Integer
Dim currentversionnumber As Integer
Dim script1() As String
Dim script2() as String
Dim combinedLines As New List(Of String)
script1 = System.IO.File.ReadAllLines("C:\itcd\scripts\519.sql")
script2 = System.IO.File.ReadAllLines("C:\itcd\scripts\520.sql")
For linePos As Integer = 0 To System.Math.Max(script1.Length, script2.Length) - 1
If linePos < script1.Length Then combinedLines.Add(script1(linePos))
If linePos < script2.Length Then combinedLines.Add(script2(linePos))
Next
System.IO.File.WriteAllLines("C:\itcd\scripts\new.sql", combinedLines.ToArray())
End Sub
如果要读取所有选定的文件,然后将它们组合成一个名为new.sql的文件,而无需对文件路径进行任何硬编码,我想创建某种循环。任何帮助将不胜感激。