Page 1 of 1 1
Topic Options
#68417 - 2002-07-16 11:07 PM Search text file
JasLC Offline
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
#68418 - 2002-07-16 11:16 PM Re: Search text file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Read the manual, commands are OPEN, READLINE, CLOSE. They come with an example of how to read the lines of a file. You then count the number of lines you're reading in and abort after line 3.
_________________________
There are two types of vessels, submarines and targets.

Top
#68419 - 2002-07-16 11:22 PM Re: Search text file
JasLC Offline
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 Offline
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.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#68421 - 2002-07-16 11:27 PM Re: Search text file
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear JasLC,

What is the filemask of wanted files?
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#68422 - 2002-07-16 11:31 PM Re: Search text file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Gentlemen... If JasLC is new to KiXtart, most of your replies will still leave him feeling helpless. Yes, maybe this should be in the starters forum, but none the less.

Do we have an FAQ on this? If not, can we make one. Very valuable to have I think. Question comes up a lot.

Well, I have to run off for now, but maybe someone else can show a real example of doing it.

Kent, if you can (if not there already) place it into the FAQ. Without looking myself right now, though, I think we do have one - or similar.

Top
#68423 - 2002-07-16 11:37 PM Re: Search text file
JasLC Offline
Fresh Scripter

Registered: 2002-05-29
Posts: 39
Loc: Fort Worth
The filemask is *.*
Top
#68424 - 2002-07-16 11:38 PM Re: Search text file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
NTDOC: Clearly a case of lack of information. I understood his initial question as how do I read line 3 of a file. What he apparently really wants is to retrieve a list of files from a directory.

Anyway, see the following posts:
File Input/Output Primer
DirList() - Returns an array with a list of files in a given directory
DirPlus() - a recursive dir tool
_________________________
There are two types of vessels, submarines and targets.

Top
#68425 - 2002-07-16 11:41 PM Re: Search text file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
JasLC: That filkemask would give you all files in the directory. Is that what you want?

Then the pseude-code would look like this:
code:
$array=dirlist('path2dir\*.*)
for each $file in $array
open(1,$file)
for $a=1 to 3
$line=readline(1)
next
close(1)
? $line
next



[ 16 July 2002, 23:41: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#68426 - 2002-07-17 01:07 AM Re: Search text file
JasLC Offline
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
#68427 - 2002-07-17 01:17 AM Re: Search text file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
those are the error codes from open and close.
with this it shows you lines and not those codes:
code:
$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

corrected one error too.
cheers,
_________________________
!

download KiXnet

Top
#68428 - 2002-07-17 01:33 AM Re: Search text file
MCA Offline
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.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#68429 - 2002-07-17 01:38 AM Re: Search text file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hey.
I didn't even check for the error 2 and got it right.

again mca comes to rescue with error-checking code..
and gladly can see that the syntax is kept pretty simple. [Wink]

cheers,
_________________________
!

download KiXnet

Top
#68430 - 2002-07-17 01:41 AM Re: Search text file
JasLC Offline
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: [Smile]

$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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1046 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.141 seconds in which 0.104 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org