SoyArcano Posted January 16, 2018 Posted January 16, 2018 My question is if for example i write these lines FileWriteLine($hFileOpen, "Line 1") FileWriteLine($hFileOpen, "Line 2") FileWriteLine($hFileOpen, "Line 3") can i after delete them?
iamtheky Posted January 16, 2018 Posted January 16, 2018 (edited) you can use _FileWriteToLine to delete (i imagine through after readline loop or filereadtoarray function to get the line to delete). Quote If _FileWriteToLine() is called with $iOverWrite as 1 and $sText as "", it will delete the line. Edited January 16, 2018 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
AspirinJunkie Posted January 17, 2018 Posted January 17, 2018 (edited) Or: calculate the sum of the StringLengths (+ the line breaks) set the position with FileSetPos and the calculated length sum directly ahead of the written lines. use FileSetEnd() to cut the file at this position (the part after the current position is deleted) as an alternative to the length-calculation you can use FileReadLine by using a negative line number. So for example if you do FileReadLine($hFileOpen, -4) the file pointer is standing at the end of the fourth last line. If you now use FileSetEnd() the last three lines will get deleted. Edited January 17, 2018 by AspirinJunkie
Juvigy Posted January 18, 2018 Posted January 18, 2018 If you havent saved the file you can reopen it and they will be gone.
KickStarter15 Posted January 18, 2018 Posted January 18, 2018 Try: #include <File.au3> _FileWriteToLine(@ScriptDir & "\test.txt", 3, "my replacement for line 3", True) _FileWriteToLine(@ScriptDir & "\test.txt", 3, "", False) Or #Include <Array.au3> #include <File.au3> $sFilePath = @ScriptDir & '\Files.log' Local $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.") Return False EndIf FileWriteLine($hFileOpen, "Line 2") FileWriteLine($hFileOpen, "Line 3" & @CRLF) FileWriteLine($hFileOpen, "Line 4" & @CRLF) FileWriteLine($hFileOpen, "Line 5") $aFiles = FileReadToArray($sFilePath) $content = FileRead($sFilePath) MsgBox(0,"Test",$content) ; =========================== ; if you will commented this lines, it will not delete your inserted lines in text file For $i = 0 to UBound($aFiles)-1 $content = StringRegExpReplace($content, $aFiles[$i] & '\R?', "") Next $hFile = FileOpen($sFilePath, 2) FileWrite($hFile, $content) FileClose($hFile) ; =========================== Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.
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