currently it's set so it inserts a line in a file that has the text string [content] in it from another source text file full of text lines
i need to make it so it inserts lines but not under [content] but to a specific line number, eg: set a line number so the text lines are inserted there instead of a random location under [content]
Code: Select all
#NoEnv
SetBatchLines, -1
SourcePath := "C:\Users\username\Desktop\source.txt"
TargetPath := "C:\Users\username\Desktop\New folder" ; NO CLOSING \
TargetExt := "txt" ; File type
FileRead, SourceData, %SourcePath%
SourceLines := StrSplit(SourceData, "`r`n")
MaxLines := SourceLines.Length()
Loop Files, %TargetPath%\*.%TargetExt%
{
If (A_Index > MaxLines)
ErrorExit("More files than source lines (" . MaxLines . ")!")
If !(FileObj := FileOpen(A_LoopFileLongPath, "rw"))
ErrorExit("Could not open the target file " . A_LoopFileLongPath . "!")
FileContent := FileObj.Read()
If (Pos := RegExMatch(FileContent, "Pim)^\[content\]$", Len)) {
FileObj.Pos := Pos + Len - 1
FileObj.Write("`r`n" . SourceLines[A_Index])
FileObj.Write(SubStr(FileContent, Pos + Len))
}
FileObj.Close()
If (Pos = 0)
ErrorExit(A_LoopFileLongPath . "`r`ncould not find the [content] line!")
}
ErrorExit(Msg) {
MsgBox, 16, ERROR!, %Msg%
ExitApp
}