Page 1 of 1 1
Topic Options
#39979 - 2003-05-11 01:02 AM Newbie questone
Ozmodius Offline
Fresh Scripter

Registered: 2003-05-11
Posts: 10
How can I append a line of text to the beginning of a file?
This lets me add the line at the end .. but i can't seem to find an example of adding to the beginning. Thanks for the help in advance.

(don't mind the code this is my first script, and i just started working on it today.)

----Code-----
If Exist ("c:\" + @USERID + "\v1.prf")
Exit
Else
MD ("c:\" + @userid + "\")

Copy "v1.dat" ("c:\" + @userid +"\v1.dat")

$Handle = FreeFileHandle()
IF $Handle > 0
IF Open($Handle,"c:\" + @userid + "\v1.dat", 4) = 0
$x = Writeline($Handle, "USER=" + @userid)
Close($Handle)
ENDIF
ENDIF
EndIF
exit
-------End Code-----

[ 11. May 2003, 01:03: Message edited by: Ozmodius ]

Top
#39980 - 2003-05-11 01:05 AM Re: Newbie questone
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
basically with kixtart functions you would open the old file and new file.
write the new data to the new file and then copy all lines from the old to the new.

then delete the old and there you go.
_________________________
!

download KiXnet

Top
#39981 - 2003-05-11 01:05 AM Re: Newbie questone
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You cannot. However, you can create a new file, and write the line. Then copy both files into one and you get the second text file appended to the first.
code:
shell '%COMSPEC% /c file1.txt + file2.txt file.txt'

You could also read the complete second file and the write it to the first file.

[ 11. May 2003, 01:43: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#39982 - 2003-05-11 01:07 AM Re: Newbie questone
Ozmodius Offline
Fresh Scripter

Registered: 2003-05-11
Posts: 10
Thanks a million!! .. i'll use the shell command
Top
#39983 - 2003-05-11 01:36 AM Re: Newbie questone
Ozmodius Offline
Fresh Scripter

Registered: 2003-05-11
Posts: 10
This

---code-----
shell '%COMSPEC% /c user.txt+v1.txt rename.txt'
---code-----

returned an error .. user.txt+v1.txt is not a valid command or batch process

am I doing it wrong?

Top
#39984 - 2003-05-11 01:42 AM Re: Newbie questone
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well...

you can do it after writing to the file 2:

shell "%comspec% /c type file1 >> file2"

thus all the info would be in the file2
_________________________
!

download KiXnet

Top
#39985 - 2003-05-11 01:43 AM Re: Newbie questone
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or put spaces between the '+' sign, copied the help text incorrectly.
_________________________
There are two types of vessels, submarines and targets.

Top
#39986 - 2003-05-11 01:50 AM Re: Newbie questone
Ozmodius Offline
Fresh Scripter

Registered: 2003-05-11
Posts: 10
Worked beutifully!!!! Thanks again.
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
0 registered and 1619 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.036 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