FileAppend, delete the last line

Get help with using AutoHotkey and its commands and hotkeys
Posts: 21
Joined: 13 Apr 2016, 09:06

FileAppend, delete the last line

16 Apr 2016, 10:14

I have a Programm, that writes in an csv table i used the command:

Code: Select all

FileAppend, `nTFT%count%;%MNF%;%Model%;%Size%;%GRD%;%COL%;%SN%;%Delivery%;%PAL16%;%NumberBox16%;%WK1%;%WK2%;%WK3%;%WK4%;%Info1%;%Info2%;%Info3%;Test OK;%FullyDate%, %palletdir%\%PAL16%\%PAL16%.csv
Can I delete the last line, that i wrote? maybe if i make a mistake

User avatar
Posts: 1607
Joined: 10 Feb 2014, 20:00

Re: FileAppend, delete the last line

16 Apr 2016, 16:02

There's no built-in command to delete the last line of a text file, but there are many ways to achieve it. One idea idea is to read the current file, delete the last line during or after reading, then write out a new file with the last line having been deleted (then delete the old file and rename the new one). For example, if it's a small file, FileReadLine will do the job. If it's a large file, it's better to use FileRead or Loop,Read. Another approach is to use the TF Library:

The TF call to remove the last line is:

Code: Select all

This creates an output file with the same file name as the input file, but with a suffix of _copy (the file extension stays the same). Note that if your text file has a newline character at the end, the code above will remove the newline, not what you want. In that case, the call would be:

Code: Select all

Regards, Joe

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], boiler, Chunjee, Google [Bot], Lem2001, mikeyww, thebat, XMCQCX and 48 guests