Remove from line...
Remove from line...
How can I remove all lines a in text file from line 500 to the end of the list?
Re: Remove from line...
Code: Select all
; This script deletes lines at the end of a text file
#Requires AutoHotkey v1.1.33
filePath := A_ScriptDir "\test.txt"
delFromLine := 500 ; Delete from this line number
truncateFile(filePath, delFromLine - 1)
Run % filePath
Sleep 300
MsgBox 64, Status, Done!
truncateFile(filePath, keepLines) { ; Keep a specified number of lines in a text file
Static delim := "`r`n" ; Line delimiter
If FileExist(filePath) {
FileRead txt, % filePath
If !ErrorLevel {
If pos := InStr(txt, delim,,, keepLines) {
FileRecycle % filePath
If ErrorLevel
MsgBox 48, Error, % "An error occurred while deleting the file.`n`n" filePath
Else FileAppend % SubStr(txt, 1, pos - 1 + StrLen(delim)), % filePath
}
} Else MsgBox 48, Error, % "An error occurred while reading the file.`n`n" filePath
} Else MsgBox 48, Error, % "File not found.`n`n" filePath
}
Re: Remove from line...
fyi for those working with text files, many functions in the TF lib https://github.com/hi5/TF