Old 23rd July 2015, 23:39   #1
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Find and replace text in multiple files in a directory

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:
pkonduru is offline   Reply With Quote
Old 23rd July 2015, 23:46   #2
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
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.
pkonduru is offline   Reply With Quote
Old 24th July 2015, 00:49   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,175
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 24th July 2015, 02:18   #4
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
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!
pkonduru is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
findfirst, nsis, textreplace

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump