Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Windows Script Help Urgent..

Thread Tools
 
Search this Thread
 
Old 07 January 2003, 12:37 PM
  #1  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Is there any quick function for counting the number of lines in a file stream??

I want to read the last four lines from a file.. and at the moment it seems like

lines = 0
open files stream
read file while not eof
temp = readline(Lines)
lines = lines + 1
loop

readline (lines-4)

or similar... seems an **** about tit way so to speak...

David
Old 07 January 2003, 12:52 PM
  #2  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

tried groups.google.com?
Old 07 January 2003, 02:25 PM
  #3  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

tried groups.google.com

looks like its the long way..

David
Old 07 January 2003, 02:57 PM
  #4  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

just done it with the following code Ive thrown together..

Dim strFileName
Dim fso
Dim fil
Dim ts

Const ForReading = 1
Const TristateUseDefault = -2

strfilename = "c:\test.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fil = fso.GetFile(strFileName)
Set ts = fil.OpenAsTextStream(ForReading, TristateUseDefault)

ts.ReadAll
wscript.echo ts.Line
ts.Close

Set ts = Nothing
Set fil = Nothing
Set fso = Nothing
Old 07 January 2003, 03:02 PM
  #5  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

Use a port of the unix command tail available in this archive for which you need a stuffit expander...

Call it from a script if you want
Old 07 January 2003, 03:07 PM
  #6  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

youll see why in a bit.. Ill email you the rest..
Old 07 January 2003, 03:13 PM
  #7  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

Oh, and you'd want the DOS util, not the NT util as he hasn't included the DOS stuff in the NT archive...

At least you've got it sorted
Old 07 January 2003, 03:48 PM
  #8  
TopBanana
Scooby Regular
 
TopBanana's Avatar
 
Join Date: Jan 2001
Posts: 9,781
Likes: 0
Received 0 Likes on 0 Posts
Post

Think the quickest way is to do:

set strm = tempFile.OpenAsTextStream(ForReading)
do while ( not strm .AtEndOfStream )
strm .SkipLine
loop
lines = strm.Line

If it's a huge file then it'll take a while. If not... well, it aint pretty but it works
Old 07 January 2003, 04:31 PM
  #9  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

cheers all.... i ended up with the following...

Option Explicit

' ************************************************** ********************************************
' Declare Variables etc.
' ************************************************** *********************************************

Dim strFileName, fso, fil, ts, LineCount, a, i, objFSO, objFile, objTextFile, CurrLine, Server, strLogName
Dim myArr(4)
Dim ServerList(2) ' Adjust this value for number of servers

Const ForReading = 1
Const TristateUseDefault = -2

' ************************************************** *********************************************
' Set Default Values
' ************************************************** *********************************************
strFileName = "c:\bex10.txt"

ServerList(0) = "CPL2KMBBKP01"
ServerList(1) = "CPLNTMBPRN98"
ServerList(2) = "CPL2KMBDAT01"

For Each Server in ServerList
' ************ To Be Ammended ************
strLogName = "Bex01.txt" ' To be fixed with some logic to work out the latest file.
strfileName = "\\" & Server & "\C$\Program Files\Veritas\Backup Exec\NT\Data\" & strLogName
' ****************************************

' ************************************************** *********************************************
' Create Objects
' ************************************************** *********************************************

Set fso = CreateObject("Scripting.FileSystemObject")
Set fil = fso.GetFile(strFileName)
Set ts = fil.OpenAsTextStream(ForReading, TristateUseDefault)

' ************************************************** *********************************************
' Open File and Read All - Counter will end on last line number read
' ************************************************** *********************************************

ts.ReadAll
Linecount = ts.line
ts.Close

' ************************************************** *********************************************
' Close Resources
' ************************************************** *********************************************

Set ts = nothing
Set fil = Nothing
Set fso = Nothing

' ************************************************** *********************************************
' Read lines from log.
' ************************************************** *********************************************

a = 0 ' Array Counter
i = 5 ' Line Counter

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strFileName)
Set objTextFile = objFile.OpenAsTextStream(ForReading)

Do While objTextFile.AtEndOfStream <> True
CurrLine = objTextFile.Line
If CurrLine = (Linecount-i) Then
myArr(a)=objTextFile.ReadLine
a = a + 1
i = i - 1
Else
CurrLine = objTextFile.ReadLine
End If
Loop

objTextFile.Close
Set objFSO = Nothing
Set objFile = Nothing

' Display Data
Wscript.echo vbcrlf
Wscript.echo "Job Status for Server: \\" & Server & " Reading from logfile: " & strLogName
Wscript.echo myArr(0)
Wscript.echo myArr(1)
Wscript.echo myArr(2)
Wscript.echo myArr(3)
Wscript.echo myArr(4)

Next



Old 07 January 2003, 04:32 PM
  #10  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

And I know it can be tidied a lot...
Old 01 July 2003, 01:15 PM
  #11  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

I don't know VB personally but the principles are the same; if the lines are fixed length you can (or should be able to) use some kind of seek function, otherwise you don't have any choice but to read all of the file from the beginning, maybe just keeping 4 lines in a FIFO buffer so you don't store the entire file in RAM.


[Edited by stevencotton - 1/7/2003 1:16:20 PM]
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
hardcoreimpreza
Computer & Technology Related
21
11 October 2015 03:40 PM
FuZzBoM
Wheels, Tyres & Brakes
16
04 October 2015 09:49 PM
Ganz1983
Subaru
5
02 October 2015 09:22 AM



Quick Reply: Windows Script Help Urgent..



All times are GMT +1. The time now is 03:56 AM.