&CH1; is the entity placeholder and Bld1_Ch1.sgm is the file with the contents I want to copy in the master.
Here's the latest in my code. I'm having trouble getting the replace function to work on strMasterDoc.
Code:Imports System Imports System.IO Imports System.Linq Imports System.Text Imports System.Windows.Forms Imports System.Text.RegularExpressions Public Class Form1 Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click 'Add a FolderBrowseDialog to your form designer FolderBrowserDialog1.ShowDialog() Dim searchDir As String = FolderBrowserDialog1.SelectedPath MsgBox("Search Dir " & searchDir) Dim existingFileMaster = Path.Combine(searchDir, "Bld1_Master_Document.sgm") MsgBox("fOUND MasterBuild file " & existingFileMaster) Dim lstFileChanges = CreateList(searchDir) 'The following method does NOT return an array of lines Dim strMasterDoc = File.ReadAllText(existingFileMaster) For Each fc In lstFileChanges strMasterDoc = strMasterDoc.Replace(fc.OldString, fc.NewString) Next File.WriteAllText(existingFileMaster, strMasterDoc) End Sub Private Function CreateList(selectedPath As String) As List(Of FileChanges) Dim lstFC As New List(Of FileChanges) Dim count As Integer = Directory.GetFiles(selectedPath, "*.sgm").Count-1 'MsgBox("COUNT " & count) For i = 1 To count Dim fc As New FileChanges fc.OldString = $"&CH{i};" fc.FileName = $"Chapter{i}.sgm" fc.NewString = File.ReadAllText(Path.Combine(selectedPath, fc.FileName)) lstFC.Add(fc) Next Return lstFC End Function End Class Public Class FileChanges Public Property OldString As String '&CH1.sgm Public Property FileName As String 'Chapter1.sgm Public Property NewString As String 'Contents of Chapter1.sgm, the string to insert End Class




Reply With Quote
