fix error with add text under word

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
way2000
Posts: 58
Joined: 15 Jul 2016, 08:57

fix error with add text under word

01 Oct 2018, 02:27

i have a script that adds lines from a text file list of lines to text files in the target folder

eg: add "line1" to text file under [content1]

the script adds the "line1" under [content1] but as a result it cuts [content1] to [conten

how can i make it so it doesn't cut [content1] to [conten when it adds the "line1" text under it

Code: Select all

#NoEnv
SetBatchLines, -1

SourcePath := "C:\Users\user\Desktop\New folder (5)\New Text Document.txt"
TargetPath := "C:\Users\user\Desktop\New folder (4)" ; 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)^\[content1\]$", 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 [content1] line!")
}


ErrorExit(Msg) {
   MsgBox, 16, ERROR!, %Msg%
   ExitApp
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 232 guests