#68417 - 2002-07-16 11:07 PM
Search text file
|
JasLC
Fresh Scripter
Registered: 2002-05-29
Posts: 39
Loc: Fort Worth
|
I would like to search multiple text files in a directory, pull out information from every text file, and write information into a single file.
The information that I would like to pull out of the file is line 3 of every text file, "Netware User Name is: ?????"
Thanks! Jason
|
|
Top
|
|
|
|
#68419 - 2002-07-16 11:22 PM
Re: Search text file
|
JasLC
Fresh Scripter
Registered: 2002-05-29
Posts: 39
Loc: Fort Worth
|
I have already read that, but do not know how to tell kix32 to parse through all the files... The open command requires specifying a filename.
|
|
Top
|
|
|
|
#68420 - 2002-07-16 11:25 PM
Re: Search text file
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
Take also a look at the DIR function find catch all possible files. Another solution can be the usage of FIND command to grep the specific text "Netware Username is: " from all wanted files. greetings.
|
|
Top
|
|
|
|
#68421 - 2002-07-16 11:27 PM
Re: Search text file
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear JasLC,
What is the filemask of wanted files? greetings.
|
|
Top
|
|
|
|
#68423 - 2002-07-16 11:37 PM
Re: Search text file
|
JasLC
Fresh Scripter
Registered: 2002-05-29
Posts: 39
Loc: Fort Worth
|
The filemask is *.*
|
|
Top
|
|
|
|
#68426 - 2002-07-17 01:07 AM
Re: Search text file
|
JasLC
Fresh Scripter
Registered: 2002-05-29
Posts: 39
Loc: Fort Worth
|
Hi. I am wanting to print out line 3 from every text file in a specific directory. With sealeopard's help, I have written some small code. Although, when I run the script, all it returns is a bunch of "20"s. Here is the code:
$FileName = Dir("C:\novellclient\*.*") While $FileName <> "" and @ERROR = 0 open (1,$filename) for $a=1 to 3 $line=readline(1) next close(1) ? $line $FileName = Dir() ; retrieve next file Loop
Thanks! Jason
|
|
Top
|
|
|
|
#68428 - 2002-07-17 01:33 AM
Re: Search text file
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
The error code means 2 (= the system cannot find the file specified) and 0 (= the operation completed successfully).
We have result the script a little. With IF/ENDIF we are suppressing unwanted error status codes. We also skip directories.
code:
$directory="C:\novellclient\" $filename = Dir($directory+"*.*") IF (Len($filename) <> 0) WHILE ($filename <> "") AND (@error = 0) IF GetFileAttr($directory+$filename) & 16 IF ($filename <> ".") AND ($filename <> "..") ? "entry skipped. '"+LCASE($directory+$filename)+"' is directory" ENDIF ELSE IF (Open(1,$directory+$filename) = 0) FOR $i=1 TO 3 $line=readline(1) NEXT IF Close(1) ENDIF ? "file '"+LCASE($directory+$filename)+"' -> "+$line ENDIF ENDIF $filename=Dir() ; retrieve next file LOOP ELSE ? "no files found" ENDIF
greetings.
|
|
Top
|
|
|
|
#68430 - 2002-07-17 01:41 AM
Re: Search text file
|
JasLC
Fresh Scripter
Registered: 2002-05-29
Posts: 39
Loc: Fort Worth
|
I got it working and it's great! hehe I want to especially thank Leopard and Lonkero for their help! MCA...thanks for the script and error checking, hehe. Here's my final, simple, little code that works:
$x=REDIRECTOUTPUT("c:\temp\users.txt") $FileName = Dir("C:\novellclient\*.*") While $FileName <> "" and @ERROR = 0 $nul=open (1,"c:\novellclient\"+$filename) for $a=1 to 3 $line=readline(1) next $nul=close(1) ? $line $FileName = Dir() ; retrieve next file Loop
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|