Issue getting count of lines in a file - VisualCron - Forum

Community forum

In a job triggered by a file appearing in a folder, the first task attempts to set a job variable equal to the number of rows in the file minus 2 for the header and footer rows. I am using a formula for this I found by searching in the forum here: {STRING(RowCount|{FILE(Content|g:\temp\test.txt)})}-2

The actual task looks like this:


The result ends up being "1-2" (I now realize I'll need to use a math function to do the subtraction once I get this figured out). It seems the folder\filename gets resolved to a valid path which is 1 line, then the 1 line is counted instead of the file's content's being read by the rowcount function.

What am I doing wrong? Can't one use job variables for the PATH/FILENAME in the FILE/Content function? Or do I need to resolve those first somehow before rowcount sees them?


The FILE{CONTENT|filename} is not resolving, so the ROWCOUNT sees only one line of your variable. As it is a STRING, the -2 is added to the value and you get 1-2 as result.

What you can do is using a Powershell task and using a variable as your filename.
See this post how to use a variable in powershell: Use variables in Powershell 

And with this script you get your result:

	[string] $filename
@(Get-Content $filename).Length - 2

Uses Visualcron since 2006.
Works for me with a Math function

Gentlemen, thank you for your replies. After some continued playing around with it my original try worked after removing the "-2" from the end (which I came to know was wrong anyway). Interesting that this caused the path I built not to be interpreted correctly. I suspect it causes an internal issue and stops expansion of the variables maybe.

This could be a bug as I would still expect the variables to be resolved and the rowcount to work and the "-2" to get tacked to the end though.
Scroll to Top