Page 1 of 1
Column question: Lines of text in a text file?
Posted: 08 Jan 2026 18:31
by kunkel321
Is there a straight-forward way to show this?
What I'd really like is the number of lines of code in an ahk file. I don't suspect there is an easy way to do that, but I believe that ahk files are just text files with UTF-8 encoding. So maybe the overall number of lines(?)
I have a Custom Column that uses
for the number of pages in a pdf or doc file, but it doesn't seem to work for txt or ahk.
Re: Column question: Lines of text in a text file?
Posted: 08 Jan 2026 19:01
by highend
return gettoken(readfile(<cc_item>), "count", <crlf>);
Re: Column question: Lines of text in a text file?
Posted: 08 Jan 2026 23:15
by kunkel321
highend wrote: ↑08 Jan 2026 19:01
return gettoken(readfile(<cc_item>), "count", <crlf>);
Thanks Highend! Below is the setup, if anyone is curious.
Also a follow up question: Is it possible to append a bit of text to the end, when there is a value returned? So that it will show up as, for example
234 Lns.
?

- CC 2026-01-08_14-11-48.jpg (78.6 KiB) Viewed 420 times
Re: Column question: Lines of text in a text file?
Posted: 08 Jan 2026 23:25
by highend
Concatenate it?
. " Lns.";
Re: Column question: Lines of text in a text file?
Posted: 08 Jan 2026 23:32
by kunkel321
Ah yes. I was missing the dot. This does the trick.
return gettoken(readfile(<cc_item>), "count", <crlf>) . " Lns." ;
Interestingly, I'm finding that it doesn't work on every txt file. On some of them, and all ahk files only ever show "1".
I'm guessing that the
<crlf> is the thing being counted? Maybe different types of encoding on the files(?)
<lf> seems to be a little better, but the number of lines returned on the ahk files is still a bit low...
It's also noteworthy that I have this as just one of several components in a Mixed Column...
Maybe the next calculation in the mixed column steps happen before the counts are able to finish(?) I don't think that it's a timing issue, as the same (slightly low) numbers appear after each refresh.
Re: Column question: Lines of text in a text file?
Posted: 08 Jan 2026 23:57
by highend
Probably mixed line endings...
Try this cli tool:
Adapt the <path>^^
return runret(lax("<path>\Count lines.exe" "<cc_item>"));
Re: Column question: Lines of text in a text file?
Posted: 09 Jan 2026 03:56
by jupe
You could alternatively do it like this natively without the exe, I'd assume it would be faster.
Code: Select all
$c = readfile(<cc_item>);
if ($c) {
$c = replace($c, <crlf>, <lf>);
$c = replace($c, <lf>, chr(13));
$c = gettoken($c, "count", chr(13),, 4);
return "$c Lns.";
}
@highend: that exe seems to double the line count for UTF-16 files
Re: Column question: Lines of text in a text file?
Posted: 09 Jan 2026 06:10
by highend
You're right, jupe
This version should fix it:
It requires SSE2, so almost all processors since 2005 should be able to use it (Pentium 4+)
Tested on UTF-8 (BOM & no BOM), UTF-16 LE (BOM & no BOM), UTF-16 BE (BOM & no BOM)
Your XY version fails on UTF-16 BE without BOM btw, instead of counting 5 lines for a mixed-lines-ending file it counts 9 instead.
@kunkel
For this v0.2 version you need to call it differently:
Code: Select all
return runret(lax("<path>\Count lines.exe" "<cc_item>"), 3:=2);
Re: Column question: Lines of text in a text file?
Posted: 09 Jan 2026 07:02
by jupe
Yeah UTF-16BE without BOM are pretty rare though, I guess if you didn't mind slowing down the script slightly, something like this should work in those edge cases too,
Code: Select all
$r = filetype(<cc_item>) == "Binary" ? 1201 : "";
$c = readfile(<cc_item>, 3:=$r);
if ($c) {
$c = replace($c, <crlf>, <lf>);
$c = replace($c, <lf>, chr(13));
$c = gettoken($c, "count", chr(13),, 4);
return "$c Lns.";
}
I haven't thoroughly tested it though.
Re: Column question: Lines of text in a text file?
Posted: 09 Jan 2026 20:44
by kunkel321
Cool -- Thanks Fellas! Jupe's first one does indeed seem to return the correct numbers for the txt and ahk files I'm working with. I'm curious though, when using the Count lines.exe file, what folder does the exe go in?
Re: Column question: Lines of text in a text file?
Posted: 09 Jan 2026 21:35
by highend
Wherever you like

Re: Column question: Lines of text in a text file?
Posted: 10 Jan 2026 16:41
by kunkel321
Ah yes. Now I see.