#73800 - 2003-03-04 03:40 PM
Re: determining how many lines there are in a plain txt file
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
I completely disagree with this type of approach. One should always code in an efficient way, e.g. suppressing return codes, DIMming variables, and so on. It might not make a difference in a 20-line script, however, if you have to write/test/debug/redesign 100+ (1000+, 10000+) lines of code, then those things make a huge impact/difference.
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#73801 - 2003-03-04 03:58 PM
Re: determining how many lines there are in a plain txt file
|
RobinHood
Fresh Scripter
Registered: 2001-10-11
Posts: 29
|
Jens, i agree too but what i mean was that i was going to look into the proposed code and adapt my version. When writing this 'cosmetics' comment i was in the middle of ammending. It works now so i'm off browsing through the UDF's to supress the 0000's. It might take a while before i get this suppression running since it's a feature i haven't used yet.
I'll post the uncleaned version further down this topic ( someone might find it usefull for his or her problem ).
Edwin
SHELL 'CMD /C DEL u:\FS-Compare\detectdirs.txt' SHELL 'CMD /C DIR \\serverA\pathA$\*.* /AD /B >> u:\FS-Compare\detectdirs.txt' SHELL 'CMD /C DIR \\serverB\pathB$\*.* /AD /B >> u:\FS-Compare\detectdirs.txt' SHELL 'CMD /C DEL u:\FS-Compare\rmtshare.txt' SHELL 'CMD /C RMTSHARE \\serverB >> u:\FS-Compare\rmtshare.txt'
open(1,"u:\FS-Compare\stripped-result.txt",5) open(2,"u:\FS-Compare\rmtshare.txt") open(3,"u:\FS-Compare\detectdirs.txt") open(4,"u:\FS-Compare\problem-log.txt",5)
$line = readline(2) $mxcount1 = 0 $mxcount2 = 0 $check = readline(3)
while @ERROR = 0 IF INSTR($line,"pathB\") OR INSTR($line,"pathA\") $MyArray = split($line,"$") WriteLine( 1 , $myarray[0] + @CRLF) ENDIF $line = readline(2) loop
close(1) close(2)
open(5,"u:\FS-Compare\stripped-result.txt") $stripp = readline(5)
while @ERROR = 0 $buildmx1array = $stripp $stripp = readline(5) $mxcount1 = $mxcount1 + 1 loop
close(5)
while @ERROR = 0 $buildmx2array = $stripp $check = readline(3) $mxcount2 = $mxcount2 + 1 loop
close(3)
open(6,"u:\FS-Compare\stripped-result.txt") $stripp = readline(6) open(7,"u:\FS-Compare\detectdirs.txt") $check = readline(7)
? "There are " + $mxcount1 + " shares and " + $mxcount2 + " directories" writeline(4,"There are " + $mxcount1 + " shares and " + $mxcount2 + " directories" +@CRLF )
FOR $count1 = 1 TO $mxcount1 STEP 1 $trigger = 0 FOR $count2 = 1 TO $mxcount2 STEP 1 IF INSTR($tripp,$check) $trigger = $trigger + 1 $check = readline(7) ENDIF NEXT IF $trigger = 0 WriteLine(4, @CRLF + $stripp + " cannot be linked to an existing directory " + @CRLF) ENDIF $stripp = readline(6) NEXT
close(4) close(6) close(7)
That's it for the uncleaned version. The cleaned up one will come in a while. Note that i used some generic servernames & pathnames . The boss wouldn't have liked it if i had left the complete path & exact servernames in it.
|
|
Top
|
|
|
|
#73803 - 2003-03-04 05:09 PM
Re: determining how many lines there are in a plain txt file
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Edwin,
Jens is right.. It reads much easier when you do the [CODE] .. [/CODE] and simply use the "Code" button below while doing a post.
Kent
|
|
Top
|
|
|
|
#73804 - 2003-03-05 07:16 AM
Re: determining how many lines there are in a plain txt file
|
RobinHood
Fresh Scripter
Registered: 2001-10-11
Posts: 29
|
Kent, both of you are right and i'm angry about not having discovered the bug that's still in the code. For one or another bizarre reason the code works fine if i key in the data manually into the stripped-result & detectdirs text files. I was so angry on myself that i woke up at 3am and immediately fired up the laptop. The reason why seems bizarre since the double for next loop works fine . It seems that one of the 2 variables $stripp or $check contains a character too much ( possibly related to the dos commands i issue at the beginning of the script ).
Jens, i'll use the code button next. If you see me forgetting it again remind me ( i tend to forget these layout things from time to time ).
I'm going to try and access the getlinecount() UDF again today ( got a server timeout all day yesterday ) and also look for a way around my problem.
|
|
Top
|
|
|
|
#73805 - 2003-03-05 02:34 PM
Re: determining how many lines there are in a plain txt file
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Edwin,
Looks like the Scriplogic site is rolling again..
Here is what I used this morning:
code:
; - Code taken from - http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=GetLineCount CLS BREAK ON
$Lines=GetLineCount('c:\CONFIG.NT') $Lines1=GetLineCount('c:\Windows\system32\CONFIG.NT') 'Your 1 file has ' + $Lines + ' lines.' ? 'Your 2 file has ' + $Lines1 + ' lines.' ? Get $c
FUNCTION GetLineCount($sFileSpec) ; $sFileSpec is a string containing a file specification ; GetLineCount() returns an integer with the number of lines in the file ; or -1 if there is an error. DIM $vTmp, $iFileNum $sFileSpec = '' + $sFileSpec $iFileNum = 7 $GetLineCount = -1 IF Exist($sFileSpec) IF Open($iFileNum,$sFileSpec) = 0 $GetLineCount = 0 $vTmp = ReadLine($iFileNum) WHILE @ERROR = 0 $GetLineCount = $GetLineCount + 1 $vTmp = ReadLine($iFileNum) LOOP $vTmp = Close($iFileNum) ENDIF ENDIF ENDFUNCTION ; GetLineCount()
|
|
Top
|
|
|
|
#73806 - 2003-03-06 09:09 AM
Re: determining how many lines there are in a plain txt file
|
RobinHood
Fresh Scripter
Registered: 2001-10-11
Posts: 29
|
First of all sorry for being so silent all day yesterday. As i was a bit frustrated the day before ( from not getting the script working ) i woke up at 3am yesterday and scrapped the script completely. This time i reworked it and used a couple of UDF's to simplify my work. I know, it's like cheating but , IT works. I've copied everything to my laptop just now. You can bet on it that i'll be studying those UDF's " getlinecount() / isinarray() and pipe()" . Using them allowed me to reduce and simplify the code a lot. A big thank you to the authors of these UDF's ( sealeopard, i think you know who i'm talking about ).
code:
; Issuing a couple of good old DOS commands
SHELL 'CMD /C del u:\FS-Compare\rmtshare.txt' SHELL 'CMD /C RMTSHARE \\server >> u:\FS-Compare\rmtshare.txt'
; here the script starts for real
open(1,"u:\FS-Compare\stripped-result.txt",5) open(2,"u:\FS-Compare\rmtshare.txt") open(3,"u:\FS-Compare\bruhub-nok.txt",5) open(4,"u:\FS-Compare\bruhub-ok.txt",5)
while @ERROR = 0 IF INSTR($line,"y:\path\") $MyArray = split($line,"$") WriteLine( 1 , $myarray[0] + @CRLF) ENDIF $line = readline(2) loop
; counting the lines in detectdirs.txt & stripped-result.txt
close(1) open(1,"u:\FS-Compare\stripped-result.txt")
$searchstring = readline(1)
$maxstripcount = getlinecount('u:\fs-compare\stripped-result.txt')
;Retrieving the directories use y: /del use y: "\\server\path$"
$dirarray = PIPE('DIR y:\*.* /AD/B')
; Here starts the compare section
FOR $stripcount = 1 to $maxstripcount STEP 1 IF NOT ISINARRAY($dirarray, $searchstring) WRITELINE(3, $searchstring + @CRLF ) ELSE WRITELINE(4, $searchstring + @CRLF ) ENDIF $searchstring = readline(1) NEXT
close(1) close(2) close(3) close(4)
Note that i left out the code bit of each function since you can refer to that in the different UDF libraries. Anyone, feel free to use this and rework it for your purpose. And i did not supress the zero's for a good reason. I kept them as a progress indicator. This may be a stupid idea but it's better then thinking your script has locked up when it takes a bit longer.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 302 anonymous users online.
|
|
|