|
|
#1 |
|
Junior Member
Join Date: Jan 2005
Posts: 4
|
how to edit a text file?
Hi,
I'm installing an app with a config file that looks something like this: <config> <path>c:\my_dir\my.file</path> </config> I need to change "c:\my_dir" to the installation directory at install time (ex. to "d:\another_dir") Can anyone help me get started? A simple find and replace text in a file would be perfect. Any help is greatly appreciated, Jed |
|
|
|
|
|
#2 |
|
Debian user
(Forum King) Join Date: Jan 2003
Location: Arch land
Posts: 4,917
|
at this time there isn't "teh" xml parser plugin ....
![]() but you can parse that file.... isn't that hard... just loop with strstr until you'll find <path>... * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with MATE. * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with MATE. |
|
|
|
|
|
#4 |
|
Junior Member
|
There are several text replacement examples provided with NSIS, but I found that I needed to dig a little deeper to come up with what I needed to do exactly what you're requesting. Here's the code that I came up with (which is cobbled together from a couple different sources, and then slightly modified):
Function searchReplace ClearErrors StrCpy $OLD_TEXT_EOL "$OLD_TEXT$CRLF" FileOpen $SOURCE_FILE $FILENAME "r" GetTempFileName $TMP_FILE FileOpen $TARGET_FILE $TMP_FILE "w" loop: FileRead $SOURCE_FILE $CURRENT_STRING IfErrors done StrCmp $CURRENT_STRING $OLD_TEXT_EOL 0 compare_without_eol FileWrite $TARGET_FILE $NEW_TEXT FileWrite $TARGET_FILE $CRLF ; MessageBox MB_OK "Replaced text $OLD_TEXT" Goto loop compare_without_eol: StrCmp $CURRENT_STRING $OLD_TEXT 0 write_original_string FileWrite $TARGET_FILE $NEW_TEXT ; MessageBox MB_OK "Replaced text $OLD_TEXT" Goto loop write_original_string: FileWrite $TARGET_FILE $CURRENT_STRING Goto loop done: FileClose $SOURCE_FILE FileClose $TARGET_FILE Delete $SOURCE_FILE CopyFiles /SILENT $TMP_FILE $FILENAME Delete $TMP_FILE FunctionEnd To call this function: StrCpy $OLD_TEXT "c:\my_dir" StrCpy $NEW_TEXT "${INSTDIR}" Call searchReplace |
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|