Hi Guys,
I have been trying to replace text in multiple files in a directory but have not been successful. Here is my code. My code only replaces the first file and does not do the replace on the remaining files.
FindFirst $0 $1 "$INSTDIR\tools\*.bat"
FileLoop:
StrCmp $1 "" DoneFileLoop ;Check for no files
DetailPrint $1 ;Print file name
${textreplace::ReplaceInFile} "$INSTDIR\tools\$1" "$INSTDIR\tools\$1" "\jre" "\..\jre" "/S=1 /C=1 /AO=1" $0
FindNext $0 $1 ;Get the next file from the list
goto FileLoop ;Go back to the top and check for no files
DoneFileLoop:
Find and replace text in multiple files in a directory
4 posts
Have tried the RecFind
I have tried the RecFind.nsh that was in the NSIS source page but this plugin does not accept wild cards for files in directories.
${RecFindOpen} "C:\Program Files\NSIS\Projects" $R0 $R1
the above works fine but
${RecFindOpen} "C:\Program Files\NSIS\*" $R0 $R1
does not work.
I have tried the RecFind.nsh that was in the NSIS source page but this plugin does not accept wild cards for files in directories.
${RecFindOpen} "C:\Program Files\NSIS\Projects" $R0 $R1
the above works fine but
${RecFindOpen} "C:\Program Files\NSIS\*" $R0 $R1
does not work.
In the first example you are using $0 in the replace call but the find handle is already stored there. I'm assuming the detailprint does not appear for the second file?...
You are also missing a FindClose at the end...
You are also missing a FindClose at the end...
Thank you
Hi Anders,
Thanks a lot!! I didn't realize the text replace had the same variable with the the FindNext.
Also added FindClose $0.
Works perfectly now!
Really appreciate it!
Hi Anders,
Thanks a lot!! I didn't realize the text replace had the same variable with the the FindNext.
Also added FindClose $0.
Works perfectly now!
Really appreciate it!