minder Posted August 17, 2011 Share Posted August 17, 2011 New User Sorry I can’t work this one out; I’m trying to add a new line of text to the beginning of a text file without deleting the original line, I got this example, but I don’t know how this can be achieve, I would be grateful if you point me in the right direction. Thanks for your helpFileWriteLine.au3 Link to comment Share on other sites More sharing options...
Juvigy Posted August 17, 2011 Share Posted August 17, 2011 #include <Constants.au3> Local Const $sFile = "c:\hello.txt" $hFile = FileOpen($sFile, 0) $chars = FileRead($hFile) FileClose($hFile) $hFile = FileOpen($sFile, 2) FileWrite($hfile, "Line1"& @CRLF & $chars) FileClose($hfile) ShellExecute("c:\hello.txt") Link to comment Share on other sites More sharing options...
hannes08 Posted August 17, 2011 Share Posted August 17, 2011 (edited) _FileWriteLine_top("myfile.txt","My Line") Func _FileWriteLine_top($file, $txt) $txt &= @CRLF & FileRead($file) $fh = FileOpen($file, 1) If $fh = -1 Then Return SetError(1, 0, 0) Local $iWriteFile = FileWriteLine($fh, $txt) Local $iRet = FileClose($fh) If $iWriteFile = -1 Then Return SetError(2, $iRet, 0) Return $iRet EndFunc Adapted from _FileWriteLog() Edited August 17, 2011 by Hannes123 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
minder Posted August 17, 2011 Author Share Posted August 17, 2011 Thank you so much Link to comment Share on other sites More sharing options...
ASut Posted August 17, 2011 Share Posted August 17, 2011 #include <File.au3> ;Example: Write to line 3 of c:\test.txt REPLACING line 3 _FileWriteToLine("c:\test.txt", 3, "my replacement for line 3", 1) ;Example: Write to line 3 of c:\test.txt NOT REPLACING line 3 _FileWriteToLine("c:\test.txt", 3, "my insertion", 0) From the help file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now