Hello,

Below is the contents of my linecounter.vbs file, which I hoped was
going to be useful in telling me how many lines a text file includes,
but seems to max out at 65,000 (give or take) even though I know my
files are over 800,000 lines of text. Any suggestions? I'm obviously
oversimplifying or else this wouldn't be a problem.

Thanks,
Eric

----linecounter.vbs--------------------------------------------
Dim objArgs
Set objArgs = WScript.Arguments

TgtFile = objArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(TgtFile)
ra = f.ReadAll
msg = objArgs(0) & vbcrlf
msg = msg & " line count: " & f.Line

WScript.Echo msg
--(end)------------------------------------------------------------

Re: What's wrong with my line counter script? by Tom

Tom
Thu Mar 13 15:56:33 CDT 2008

On Mar 13, 4:32 pm, Eric Bragas <ericbra...@yahoo.com> wrote:
> Hello,
>
> Below is the contents of my linecounter.vbs file, which I hoped was
> going to be useful in telling me how many lines a text file includes,
> but seems to max out at 65,000 (give or take) even though I know my
> files are over 800,000 lines of text. Any suggestions? I'm obviously
> oversimplifying or else this wouldn't be a problem.
>
> Thanks,
> Eric
>
> ----linecounter.vbs--------------------------------------------
> Dim objArgs
> Set objArgs = WScript.Arguments
>
> TgtFile = objArgs(0)
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.OpenTextFile(TgtFile)
> ra = f.ReadAll
> msg = objArgs(0) & vbcrlf
> msg = msg & " line count: " & f.Line
>
> WScript.Echo msg
> --(end)------------------------------------------------------------

I don't have a really long text file to test with, but here is the
version I have ...

Const ForAppending = 8
Dim sInFile, nLines

if wsh.arguments.count > 0 Then
sInFile = wsh.arguments(0)
with CreateObject("Scripting.FileSystemObject")
'
' Get the number of lines in file
'
nLines = .OpenTextFile(sInFile, ForAppending).Line
end with ' fso
wsh.echo sInFile, " lines:", nLines
else
wsh.echo "No file name"
end if

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: What's wrong with my line counter script? by Pegasus

Pegasus
Thu Mar 13 16:05:18 CDT 2008


"Eric Bragas" <ericbragas@yahoo.com> wrote in message
news:19b0be87-0ed9-4b4f-ac27-2e7bce071e18@e23g2000prf.googlegroups.com...
> Hello,
>
> Below is the contents of my linecounter.vbs file, which I hoped was
> going to be useful in telling me how many lines a text file includes,
> but seems to max out at 65,000 (give or take) even though I know my
> files are over 800,000 lines of text. Any suggestions? I'm obviously
> oversimplifying or else this wouldn't be a problem.
>
> Thanks,
> Eric
>
> ----linecounter.vbs--------------------------------------------
> Dim objArgs
> Set objArgs = WScript.Arguments
>
> TgtFile = objArgs(0)
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.OpenTextFile(TgtFile)
> ra = f.ReadAll
> msg = objArgs(0) & vbcrlf
> msg = msg & " line count: " & f.Line
>
> WScript.Echo msg
> --(end)------------------------------------------------------------

There are some limitations with the OpenTextFile method
that do not appear to be gracefully handled by cscript.exe.
You can get around them by using the TextStream method,
e.g. like so:

TgtFile = "d:\big.txt"
Set file = fso.GetFile(TgtFile)
Set InputStream = file.OpenAsTextStream(1)
InputStream.ReadAll
msg = msg & " line count: " & InputStream.Line



Re: What's wrong with my line counter script? by Paul

Paul
Thu Mar 13 16:14:43 CDT 2008


"Eric Bragas" <ericbragas@yahoo.com> wrote in message
news:19b0be87-0ed9-4b4f-ac27-2e7bce071e18@e23g2000prf.googlegroups.com...
> Hello,
>
> Below is the contents of my linecounter.vbs file, which I hoped was
> going to be useful in telling me how many lines a text file
> includes,
> but seems to max out at 65,000 (give or take) even though I know my
> files are over 800,000 lines of text. Any suggestions? I'm
> obviously
> oversimplifying or else this wouldn't be a problem.
>
> Thanks,
> Eric
>
> ----linecounter.vbs--------------------------------------------
> Dim objArgs
> Set objArgs = WScript.Arguments
>
> TgtFile = objArgs(0)
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.OpenTextFile(TgtFile)
> ra = f.ReadAll
> msg = objArgs(0) & vbcrlf
> msg = msg & " line count: " & f.Line
>
> WScript.Echo msg
> --(end)------------------------------------------------------------

You are creating the textstream object, f, without specifying a
format, so it defaults to ASCII, according to the documentation. If
the file happens to actually be formatted as Unicode, then you may
have problems reading it properly.

You could read the first two characters (as ASCII) -- I've never seen
a Unicode file read fail in the first two characters. If they are hex
FF FE or FE FF, then the file system thinks it is Unicode and you may
have problems, unless you specify the format as Unicode.

-Paul Randall



Re: What's wrong with my line counter script? by Paul

Paul
Thu Mar 13 17:39:50 CDT 2008

My guess is that you haven't given 'f' a dimension (nor fso) and it
maxes out on the max value of a short int: 65535 to which it defaults.

What happens if you add the line 'dim fso, f' ?

cheers,

Paul

Eric Bragas wrote:
> Hello,
>
> Below is the contents of my linecounter.vbs file, which I hoped was
> going to be useful in telling me how many lines a text file includes,
> but seems to max out at 65,000 (give or take) even though I know my
> files are over 800,000 lines of text. Any suggestions? I'm obviously
> oversimplifying or else this wouldn't be a problem.
>
> Thanks,
> Eric
>
> ----linecounter.vbs--------------------------------------------
> Dim objArgs
> Set objArgs = WScript.Arguments
>
> TgtFile = objArgs(0)
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.OpenTextFile(TgtFile)
> ra = f.ReadAll
> msg = objArgs(0) & vbcrlf
> msg = msg & " line count: " & f.Line
>
> WScript.Echo msg
> --(end)------------------------------------------------------------

Re: What's wrong with my line counter script? by Todd

Todd
Thu Mar 13 21:40:45 CDT 2008


"Eric Bragas" <ericbragas@yahoo.com> wrote in message
news:19b0be87-0ed9-4b4f-ac27-2e7bce071e18@e23g2000prf.googlegroups.com...
> Hello,
>
> Below is the contents of my linecounter.vbs file, which I hoped was
> going to be useful in telling me how many lines a text file includes,
> but seems to max out at 65,000 (give or take) even though I know my
> files are over 800,000 lines of text. Any suggestions? I'm obviously
> oversimplifying or else this wouldn't be a problem.
>
> Thanks,
> Eric
>
> ----linecounter.vbs--------------------------------------------
> Dim objArgs
> Set objArgs = WScript.Arguments
>
> TgtFile = objArgs(0)
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.OpenTextFile(TgtFile)
> ra = f.ReadAll
> msg = objArgs(0) & vbcrlf
> msg = msg & " line count: " & f.Line
>
> WScript.Echo msg
> --(end)------------------------------------------------------------

If .Line method is buggy, then try this method...

ra = Split(f.ReadAll, vbcrlf)
msg = "z.vbs" & vbcrlf
msg = msg & " line count: " & Ubound(ra)


Or this method...

Do While Not f.AtEndOfStream
f.SkipLine
count = count + 1
Loop
msg = objArgs(0) & vbcrlf
msg = msg & " line count: " & count

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)