#85772 - 2002-05-27 05:44 PM
Re: Last problem to fix...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Here's an uneloquent kixtart solution, removes all occurences of $string into a tempfile, meant to be renamed to original when done. Messy business...
break on
$filename = "test.txt" $tempfile = "%temp%\test.tmp"
$string = ";Activate"
if exist($tempfile) del "$tempfile" endif
if open(1,$filename) = 0 if open(2,$tempfile,5) = 0 $line = readline(1) while @error = 0 if instr($line,$string) $pos = instr($line,$string) $newline = substr($line,1,$pos) $line = $newline + substr($line,$pos+len($string)+1) endif $rc = writeline(2,$line+@CRLF) $line = readline(1) loop $rc = close(2) endif $rc = close(1) endif
; rename tempfile to filename here
exit 1
-Shawn
|
|
Top
|
|
|
|
#85773 - 2002-05-27 05:52 PM
Re: Last problem to fix...
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
For an update we creates following example:
code:
$old_string="[old string]" ; - your old string value - $new_string="<new string>" ; - your new string value - ; $file="c:\your_file.txt" ; - your file - $file_temp="%temp%\dummy.tmp" $debug_mode="yes" IF (Exist($file) = 1) DEL $file_temp IF (Open(1,$file,2) = 0) ; -read access- IF (Open(2,$file_temp,5) = 0) ; -write access- $line=ReadLine(1) WHILE (@error = 0) IF ($debug_mode = "yes") ? " -> "+$line ENDIF $i=Instr($line,$old_string) IF ($i <> 0) IF ($i = 1) $nline=$new_string+Substr($line,Len($old_string)+1) ELSE IF ($i+Len($old_string)-1 = Len($line)) $nline=Substr($line,1,Instr($line,$old_string)-1)+$new_string ELSE $nline=Substr($line,1,Instr($line,$old_string)-1)+ $new_string+ Substr($line,Instr($line,$old_string)+Len($old_string)) ENDIF ENDIF ELSE $nline=$line ENDIF IF ($debug_mode = "yes") ? " --> "+$nline ENDIF IF (WriteLine(2,$nline+CHR(13)+CHR(10)) <> 0) ENDIF $line=ReadLine(1) LOOP IF Close(2) ENDIF ENDIF IF Close(1) ENDIF ? IF (Exist($file_temp) = 1) COPY $file_temp $file /H IF (@error <> 0) ? "Warning KIX: update "+Ucase($file)+" returns error @error (@serror)" ELSE DEL $file_temp ENDIF ? "update "+Ucase($file)+" file." ENDIF ENDIF ? "update completed." ELSE ? "already updated." ENDIF
An example:
code:
[old string]123456789 123[old string]456789 123456789[old string]
becomes
code:
<new string>123456789 123<new string>456789 123456789<new string>
with screen output
code:
-> [old string]123456789 --> <new string>123456789 -> 123[old string]456789 --> 123<new string>456789 -> 123456789[old string] --> 123456789<new string>
update c:\your_file.tx file. update completed.
Greetings.
btw: we must take some precaution for a known flushing problem with write-buffers. We are only use the WriteLine functions. To prevent this kind of problems. [ 27 May 2002, 18:23: Message edited by: MCA ]
|
|
Top
|
|
|
|
#85774 - 2002-05-27 06:11 PM
Re: Last problem to fix...
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
In case anyone needs it I have just place Qreplace.exe on my website's Perl Utilities Page. It is a commandline tool that will replace "OldText" with "NewText" in multiple files as defined by a file specification that supports wildcards. Any file modified will hav the original data write to $file.BAK.
Sorry, I just fould it easier to to provide this then write a ton of KixTart code.
I see that MCA had some code available.
|
|
Top
|
|
|
|
#85775 - 2002-05-27 07:41 PM
Re: Last problem to fix...
|
Rvdeej
Fresh Scripter
Registered: 2002-05-27
Posts: 20
Loc: Bruxelles
|
Thanks again fellas...
My work is done...
I'll be helping out myself in this forum since it seem to work fine here....
Thanks again...
_________________________
Rvdeej
|
|
Top
|
|
|
|
#85776 - 2002-05-27 07:58 PM
Re: Last problem to fix...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Well, officially, this forum is for COM related scripts and questions only (like your first question - spot on), but general scripting questions should be posted to the scripts forum. But no worries because most members use the "Todays Active Topics" view which shows all the active topics, from all the forums. Actually, the scripts forum is probably the most "viewed" area anyways. Its like the "Kixtart Lounge"
-Shawn
|
|
Top
|
|
|
|
#85778 - 2002-05-27 09:01 PM
Re: Last problem to fix...
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Hi,
Possible you know already in what kind of "Lounge" the Second Millenium guys live.
#topics description by Infopop (= UBB site) 0 Newster 25 Regular 50 Fanastic 100 Mad Poster 500 Merga Poster 1000 Elite Poster 1500 Elite Group 2000 No Life!!!
Possible that you know what kind of description fits the 2500th guys. greetings.
(our reaction 2600 to the board)
|
|
Top
|
|
|
|
#85779 - 2002-05-27 09:58 PM
Re: Last problem to fix...
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
How about a KiX-adict ?
But i would rather grade the number of posts as level of helpfullnes and desire to learn from other helpfull people
-Erik
|
|
Top
|
|
|
|
#85780 - 2002-05-27 11:20 PM
Re: Last problem to fix...
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
LOL, or maybe a KiXaholic ? (as in: I've got to kix this scripting habit I have!) - or maybe the ratings wrap-around, you know, I would be a No-Life-Mega-Poster, so would MCA ... Les would be a No-Life-Fantasic ! What you think of that Les ?
-Shawn
|
|
Top
|
|
|
|
#85781 - 2002-05-28 05:05 AM
Re: Last problem to fix...
|
MCA
KiX Supporter
   
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
Dear,
We hope we doesn't become like the guy who make those member descriptions. He may now looks like

We like the name "Artist". Artists aren't very common persons. Sometimes artists may looks like a little bit strange. Artists think mostly in a strange way. Paintings from f.e. Modriaan are very simple, but we can't imitate him. Artists are very creative. Good artists know what they are doing.
We agree with kholm that guys like Shawn, Bryce, LLigetfa, NTDOC and other Millenium guys are trying to help. Specially in those situations:

greetings. [ 28 May 2002, 10:09: Message edited by: MCA ]
|
|
Top
|
|
|
|
#85782 - 2002-05-28 05:44 AM
Re: Last problem to fix...
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
|
|
Top
|
|
|
|
#85784 - 2002-05-28 06:22 PM
Re: Last problem to fix...
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
if there is one, they have to have the meetings here, or no one will show up.
I vote for fanatic.
I use many resourcekit and freeware utilities, but I don't hang out on their support sites.
How about the first poster to hit 5000 gets an iMac for therapy purposes... or would methadone be more appropriate.
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 764 anonymous users online.
|
|
|