WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Files and strings
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
Megiddo_Guest
Guest

Registered: Not Yet
From:

Files and strings

How can I search for a string in a file and replace that found string with the contents of another file?

The only way I've found so far involves strings, but the strings aren't large enough to hold the file... any help or suggestions?

Quick Link | Report this post to a moderator | IP: Logged

Old Post 06-03-2005 05:57 AM
Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

code:
Name "Output" OutFile "Output.exe" !include "TextFunc.nsh" !insertmacro LineFind !include "WordFunc.nsh" !insertmacro WordFind Var PMEMORY Var SIZE Section StrCpy $0 "C:\Input.txt" #File to replace in StrCpy $1 "C:\Output.txt" #File result StrCpy $R0 "ReplaceIt" #Replace string StrCpy $R1 "C:\Source.txt" #File replace with content StrCpy $R2 "0" #Changes to made ("0" - replace all) StrCpy $R3 "0" #Count of changes (start with "0") ${LineFind} "$0" "$1" "1:-2 -1" "LineFindCallback" IfErrors 0 +2 MessageBox MB_OK "Error" MessageBox MB_OK "Changes: $R3" SectionEnd Function LineFindCallback StrCmp $PMEMORY '0' end begin: ${WordFind} "$R9" "$R0" "E+1{" $1 IfErrors freemem FileWrite $R4 "$1" StrCmp $PMEMORY '' 0 write FileOpen $1 $R1 a FileSeek $1 0 END $SIZE System::Alloc $SIZE Pop $PMEMORY FileSeek $1 0 SET System::Call 'kernel32::ReadFile(i r1, i $PMEMORY, i $SIZE, t.,)' FileClose $1 write: IntOp $R3 $R3 + 1 System::Call 'kernel32::WriteFile(i R4, i $PMEMORY, i $SIZE, t.,)' ${WordFind} "$R9" "$R0" "+1}" $R9 StrCmp $R3 $R2 0 begin freemem: StrCmp $PMEMORY '' end StrCmp $R7 -1 +2 StrCmp $R3 $R2 0 end System::Free $PMEMORY StrCpy $PMEMORY 0 end: Push $0 FunctionEnd
Script use headers

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 06-03-2005 09:41 AM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 09:36 AM. Post New Thread    Post A Reply
  Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Files and strings
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON