Hello,
I have one simple question..
How can I use "FileAppend" to write a certain text in a certain line?
Thanks
File append in specific line (Possible?)
Re: File append in specific line (Possible?)
Try this:
I hope that helps.
- run the script
- press F12 three times
- check the effect of 3 insertions at Line #8 into the script
Code: Select all
Count := 0
;-------------------------------------------------------------------------------
F12:: InsertLine("; Hi " ++Count, A_ScriptFullPath, 8) ; hotkey for testing
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
InsertLine(Line, File, Pos) { ; insert a Line of text into File at Pos
;-------------------------------------------------------------------------------
FileRead, Content, %File%
; split Content into Front and Back
Loop, Parse, Content, `n, `r
If (A_Index < Pos)
Front .= A_LoopField "`n"
Else
Back .= A_LoopField "`n"
FileDelete, %File%
FileAppend, % Front Line "`n" Back, %File%
}
Re: File append in specific line (Possible?)
If you need to do more there is the TF library with 40+ functions incl. TF_InsertLine @ https://github.com/hi5/TF
Re: File append in specific line (Possible?)
With InStr you can get the nth occurrence of a string.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: File append in specific line (Possible?)
First of all thanks for the answer but..wolf_II wrote:Try this:
- run the script
- press F12 three times
- check the effect of 3 insertions at Line #8 into the script
I hope that helps.Code: Select all
Count := 0 ;------------------------------------------------------------------------------- F12:: InsertLine("; Hi " ++Count, A_ScriptFullPath, 8) ; hotkey for testing ;------------------------------------------------------------------------------- ;------------------------------------------------------------------------------- InsertLine(Line, File, Pos) { ; insert a Line of text into File at Pos ;------------------------------------------------------------------------------- FileRead, Content, %File% ; split Content into Front and Back Loop, Parse, Content, `n, `r If (A_Index < Pos) Front .= A_LoopField "`n" Else Back .= A_LoopField "`n" FileDelete, %File% FileAppend, % Front Line "`n" Back, %File% }
Thats good but not that what i need :/
Let´s say i have two files called text.txt and insert.ahk, i open insert and it insert the text into text.txt
I already tryed F12:: InsertLine("; Hi " MyPath, 8)
But i get an Error message
Re: File append in specific line (Possible?)
Try F12:: InsertLine("; Hi", MyPath, 8) notice the two , around MyPath.
Re: File append in specific line (Possible?)
How can i just show you my love ?, thanks <3wolf_II wrote:Try F12:: InsertLine("; Hi", MyPath, 8) notice the two , around MyPath.