Hi all,
I have several SQL Files and a BAT File in a directory(including subdirectories). In all these files, I need to replace "C:\THIS" with "E:\THAT".
How can I do that? I also went through "Afrow_UK" Archive Page(http://nsis.sourceforge.net/archive/....php?userid=87).
Sreedhar
Replace a String with an other in all Files
5 posts
Maybe Instructor's File-, Text-, Word-functions will help you.
i usually use ReplaceInFile for that
Script to find all files (I don't remember what extentions have SQL files) in directory "C:\MySQL" with subdirectories and replace "C:\THIS" with "E:\THAT" (It's only for text files, if the directory contain binary file it will be corrupted, but you can specify directly what files to search)
Script used headersName 'Output'
OutFile 'Output.exe'
!include "FileFunc.nsh"
!include "TextFunc.nsh"
!include "WordFunc.nsh"
!insertmacro Locate
!insertmacro LineFind
!insertmacro WordReplace
Section
${Locate} "C:\MySQL" "/L=F /M=*.*" "LocateCallback"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function LocateCallback
${LineFind} "$R9" "$R9" "1:-1" "LineFindCallback"
IfErrors 0 +3
MessageBox MB_YESNO "Error. Continue?" IDYES +2
StrCpy $0 StopLocate
Push $0
FunctionEnd
Function LineFindCallback
${WordReplace} '$R9' 'C:\THIS' 'E:\THAT' '+' $R9
Push 0
FunctionEnd
Script to find all *.sql and *.bat files in directory "C:\MySQL" with subdirectories and replace "C:\THIS" with "E:\THAT"
Script used headersName 'Output'
OutFile 'Output.exe'
!include "FileFunc.nsh"
!include "TextFunc.nsh"
!include "WordFunc.nsh"
!insertmacro Locate
!insertmacro GetFileExt
!insertmacro LineFind
!insertmacro WordReplace
Section
${Locate} "C:\MySQL" "/L=F" "LocateCallback"
IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd
Function LocateCallback
${GetFileExt} "$R7" $1
StrCmp $1 "bat" linefind
StrCmp $1 "sql" linefind
goto end
linefind:
${LineFind} "$R9" "$R9" "1:-1" "LineFindCallback"
IfErrors 0 +3
MessageBox MB_YESNO "Error. Continue?" IDYES +2
StrCpy $0 StopLocate
end:
Push $0
FunctionEnd
Function LineFindCallback
${WordReplace} '$R9' 'C:\THIS' 'E:\THAT' '+' $R9
Push 0
FunctionEnd