mIRC Homepage
I am trying to use the /write command to delete the last line in a text file (which is a blank line). I tried using:

/write -d file.txt

as the Mirc help says not specifying a line number will remove the last line in a file. In fact, this will remove the last line in a file that contains any text, but if the last line is blank, it will remain!

I also tried using $crlf to remove any carriage returns. This will remove blank lines in a text file EXCEPT for the last line! Can someone please help me?

Thanks in advance.
mirc automatically adds a CRLF as the last line when it writes to the file, but I don't see why this is a problem since that last line is ignored (for example, $lines() does not include that last line). Anyway, if you want to remove the ending CRLF you can use /btrunc:
Code:
/btrunc file.txt $calc($file(file.txt) - 2)



You can also check if the file ends in CRLF:
Code:
//bread file.txt $calc($file(file.txt) - 2) 2 &a | if ($bvar(&a,1-) == 13 10) { do stuff }
/write -dl $lines(filename.txt) filename.txt
That won't delete the empty line at the end (the CRLF), it will delete the one before that, which will probably be a line of text. That's what I meant that mirc ignores the last line if it's a CRLF. Both /write and $lines 'ignore' the last blank line.

/write always appends that blank line at the end of the file so I don't see any other way than binary commands.
Ooops. Sorry, I misread the question.
LOL im sorry but i cant resist no longer

<funny remark>
Well you could locate the file itself on your computer...When you do this click on the text file you want to open it....then go to the last line in the text file and do the following:

1. highlight the last line in the file and click delete
2. Save the file since it has changed
</funny remark>

Ok you now may go back to the original discussion now that i have said this i can go back to not hiding my laughter LOL
thanks for sitting through my B/S
© mIRC Discussion Forums