Page 1 of 1 1
Topic Options
#162572 - 2006-05-28 10:02 PM Edit a batch file
jhdvy Offline
Fresh Scripter

Registered: 2002-03-22
Posts: 44
Loc: New Jersey
Hi, is there an easy way to remove a line in a batch file using kixtart?

Thanks!

Top
#162573 - 2006-05-28 10:15 PM Re: Edit a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yes

Open(1,$x) read
Open(2,$y) write
Readline(1)
; analyze whatever
Writeline(2)
Loop
Close(1)
Close(2)
Copy $y $x
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#162574 - 2006-05-28 10:18 PM Re: Edit a batch file
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could use readline and writeline.
If you know what the contents of the line you want to remove is something like this should work.

Code:

$rc = open (1, "somefile.bat",2)
$rc = open (2, "c:\somenewfile.bat", 5)
;
$line = readline (1)
;
While @error <> "0"
if $line <> "contents of the line to beremoved"
$rc = writeline (2, $line + @crf)
else
?$line + " has not been written to the new file."
endif
$line = Readline (1)
loop
;
$rc = close(1)
$rc = close(2)
;
move "c:\somefile.bat" "c:\somefile.old"
move "c:\somenewfile.bat" "c:\somefile.bat"



[edit]
Les got there first
[/edit]


Edited by Mart (2006-05-28 10:19 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#162575 - 2006-05-29 12:54 AM Re: Edit a batch file
jhdvy Offline
Fresh Scripter

Registered: 2002-03-22
Posts: 44
Loc: New Jersey
Thanks Mart... This is exactly what I need. One more question though. If I want to delete line 12 for example what would I change in your code?

Thanks again.

Top
#162576 - 2006-05-29 01:19 AM Re: Edit a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You don't need to change a thing. It already deletes the line.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#162577 - 2006-05-29 01:28 AM Re: Edit a batch file
jhdvy Offline
Fresh Scripter

Registered: 2002-03-22
Posts: 44
Loc: New Jersey
That's strange. When I run this it deleted the contents of the whole file.
Top
#162578 - 2006-05-29 01:41 AM Re: Edit a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
So, what is the contents of the line you want to delete and what did you put between quotes on the following line?
if $line <> "contents of the line to beremoved"
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#162579 - 2006-05-29 01:44 AM Re: Edit a batch file
jhdvy Offline
Fresh Scripter

Registered: 2002-03-22
Posts: 44
Loc: New Jersey
As a test I added a line to my .bat file containing
contents of the line to beremoved

as in the example and the enite contents of the .bat file get deleted.

I didn't change a this from the example.

Thanks

Top
#162580 - 2006-05-29 02:09 AM Re: Edit a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... you need to fix all of Mart's bugs first.
Code:

$rc = open (1, "c:\somefile.bat",2)
$rc = open (2, "c:\somenewfile.bat", 5)
;
$line = readline (1)
;
While @error = 0
if $line <> "contents of the line to beremoved"
$rc = writeline (2, $line + @crlf)
else
?$line + " has not been written to the new file."
endif
$line = Readline (1)
loop
;
$rc = close(1)
$rc = close(2)
;
move "c:\somefile.bat" "c:\somefile.old"
move "c:\somenewfile.bat" "c:\somefile.bat"

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#162581 - 2006-05-29 02:10 AM Re: Edit a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
add "@error ?" line after the open statement and after writeline.
_________________________
!

download KiXnet

Top
#162582 - 2006-05-29 02:23 AM Re: Edit a batch file
jhdvy Offline
Fresh Scripter

Registered: 2002-03-22
Posts: 44
Loc: New Jersey
Thanks. I will give this a try.
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 641 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.063 seconds in which 0.026 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