PRODUCT






Home









Free Download








Installation Instructions





FAQ





FAQ








Ask A Question





LEARN SCRIPTING





Overview








Lesson 1








2


3


4


5








Exam





SAMPLE SCRIPTS





Computer








Internet








Administrators








Developers








Data








Miscellaneous





HELP / DOCUMENTATION





Commands








Automated Internet








Automated Editors








Sample Scripts








Precompiled Functions








System Features






  Sample Script - SS_CountLines

( Some of the sample scripts may not be reproduced correctly in html because those scripts, especially web-related scripts, have html tags such as < tr > in their code.

For an accurate, copy-and-paste'able text version of this script, see SS_CountLines.txt . )



#####################################################################
# SCRIPT: SS_CountLines
#
# This script counts the number of lines in files whose names match a given
# criterion in a given directory.
#
# The file name criterion is assigned using FVA (Forward Variable Assignment)
# for str variable $files. The value of $files is of form
# "*.html", "*.js", "*.cpp", "*.h", etc.
#
# The directory name is assigned using FVA
# for str variable $dir. The value of $dir is of form
# "C:/ABC/DEF", ".", etc.
#
# This script can be stored and edited as necessary, in a text file
# called SS_CounteLines.txt in a directory in your $path . The script can then be called as
#
# script SS_CountLines.txt dir("C:/myproject") files("*.cpp")
#
#####################################################################

# Declare FVA variables.
var str files
var str dir

# Get the list of files in variable fileList.
var str fileList
script SS_ListFiles.txt dir($dir) files($files) > $fileList

# Declare variables where we will save counts of individual files.
var int c # all lines
var int nb # non-blank lines

# Declare variables where we will save total counts for all files.
var int totalc # sum-total of all lines
var int totalnb # sum-total of all non-blank lines

# Declare variable where we will store file count.
var int fileCount

# We will store the name of the file we are working on currently, in the following.
var str file

# Go thru the $fileList one by one file.
while ($fileList<>"")
do
# Extract the next file.
lex "1" $fileList >$file

# Check if this is a flat file. We are not interested in directries.
af $file >null # We don't want to see the output.
# We only want to set the $ftype variable.
if ($ftype=="f")
do
# Yes, this is a flat file.

# Increment file count.
set $fileCount = $fileCount+1

# Collect the content of $file in $content
var str content # Content of one file at a time
repro $file >$content

# Get count and non-blank count.
set $c={len -e $content}
set $nb={len $content}

# Update total counts.
set $totalc = $totalc + $c
set $totalnb = $totalnb + $nb

done
endif

done

# Show sum-totals
echo "**********************************************************************************************************************************"
echo "Total Count of all lines:\t" $totalc ",\tTotal Count of non-blank lines:\t" $totalnb ", Total files: " $fileCount
echo "**********************************************************************************************************************************"

2008-2014, biterScripting.com. All rights reserved.
biterScripting, biterScript, biterBrowser, biterMobile, biterScripting.com, FVA (Forward Variable Assignment) are trademarks of biterScripting.com. Is it biterScripting-compatible ? is a service mark of biterScripting.com. Explorer, Unix, Windows are trademarks, service marks or other forms of intellectual property of their respective owners.