Page 1 of 1 1
Topic Options
#24223 - 2002-07-02 08:40 AM Please help with script....
cigaweed74 Offline
Fresh Scripter

Registered: 2002-04-08
Posts: 20
Here is what I want to do:
- open a text file
- read all lines in this file
- if line doesn't exist then creates it

Any idea is muchly appreciated.....

thankyou..

Top
#24224 - 2002-07-02 08:54 AM Re: Please help with script....
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Do you mean like from around page 79 of the manual?

code:
READLINE
Action
Reads a line from a file.

Syntax
READLINE (file number)

Parameter
File number
A numeric expression indicating the file number of the file to open. Possible values range from 1 to 10.

Remarks
READLINE reads a string ending in a carriage return. If successful, the function
returns the string without a carriage return. If it encounters an error, @ERROR returns an error code.

Returns
-4 File not open for reading
-3 File number not open
-2 Invalid file number specified
-1 End of file
0 Line read successfully

Example
IF Open(3, @LDRIVE + "\CONFIG\SETTINGS.INI") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
? "Line read: [" + $x + "]"
$x = ReadLine(3)
LOOP
Close (3)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF

Or are you saying that you've read this and need further help understanding it?

There is also READPROFILESTRING and WRITEPROFILESTRING and WRITELINE

Please read this first and the FAQ section on this board. If on the other hand you HAVE read this and still need assistance, then please feel free to elaborate on what exactly it is you want to do. We will be glad to help you understand it, but it makes it easier if you have at least read it and know about it.

[ 02 July 2002, 08:57: Message edited by: NTDOC ]

Top
#24225 - 2002-07-02 10:20 PM Re: Please help with script....
MCA Offline
KiX Supporter
*****

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

For other ideas see script:
code:
$search_for_line="our text we are looking for"
$file="c:\temp\our_file.txt"
;
IF (Open(1,$file,1) = 0)
$line=ReadLine(1)
$found="no"
WHILE (@error = 0)
IF (Instr($line,$search_for_line) <> 0)
$found="yes"
ENDIF
$line=ReadLine(1)
LOOP
IF Close(1)
ENDIF
;
; - append to file -
;
IF (found <> "yes")
IF (Open(1,$file,5) = 0)
IF (WriteLine(1,$search_for_line+@crlf) <> 0)
? "Warning KIX-WriteLine: error @error (@serror)."
ENDIF
IF Close(1)
ENDIF
ENDIF
ENDIF
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
#24226 - 2002-07-03 03:14 AM Re: Please help with script....
cigaweed74 Offline
Fresh Scripter

Registered: 2002-04-08
Posts: 20
Thanks MCA....your script works fine.
Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.12 seconds in which 0.094 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