我已经为此工作了一段时间,我发现的所有示例都是将给定的字符串附加到文件中,但是我无法找到在结尾附加整个文件的任何运气文件。一切都在使用 .appendAllText 或 appendText 这不适合我的需要。
我的文件是.sgm
. 在我的代码中,我首先获取所有 sgm 文件,然后检查该文件是否以 _Ch# 结尾。
我准备将文件附加到主文件,但到目前为止,我所能做的就是将文件名的字符串文本附加到主文件的末尾。
非常感谢您的帮助。最大限度
Public Class Form1
Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click
Dim searchDir As String = txtSGMFile.Text 'input field for user
'Get all the sgm files in the directory specified
Dim fndFiles = Directory.GetFiles(searchDir, "*.sgm")
'Set up the regular expression you will make as the condition for the file
Dim rx = New Regex(".*_Ch\d\.sgm")
Dim ch1 = New Regex(".*_Ch[1]\.sgm")
Dim existingFile = searchDir & "\Bld1_Master_Document.sgm"
'Loop through each file found by the REGEX
For Each file In fndFiles
If rx.IsMatch(file) Then
If ch1.IsMatch(file) Then
Dim result = Path.GetFileName(file)
Dim fileToCopy = searchDir & "\" & result
'THIS IS WHERE I WANT TO APPEND fileToCopy INTO existingFile
System.IO.File.AppendAllText(fileToCopy, existingFile)
MessageBox.Show("File Copied")
End If
'MsgBox(file)
End If
Next file
Close()
End Sub