Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 25th July 2002, 19:31   #1
Morphie
Junior Member
 
Join Date: May 2001
Location: Somewhere, I'm not sure...
Posts: 9
Send a message via ICQ to Morphie Send a message via AIM to Morphie Send a message via Yahoo to Morphie
Read, edit a single line in a file?

Is it possible for NSIS to edit a single line in a file? Like overwrite line 2 of runmefirst.bat with "move ..\setup\*.* .\setup32"
Morphie is offline   Reply With Quote
Old 25th July 2002, 19:56   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
You will have to read the file using FileRead line by line and write to another temporary file, using FileWrite. When you reach the desired line write the line you want to replace it instead of the line read. After you write your line, continue reading and writing like before. Then just replace the old file with the temporary file.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 25th July 2002, 22:29   #3
Morphie
Junior Member
 
Join Date: May 2001
Location: Somewhere, I'm not sure...
Posts: 9
Send a message via ICQ to Morphie Send a message via AIM to Morphie Send a message via Yahoo to Morphie
That... is confusing. Could you give me an example?
Morphie is offline   Reply With Quote
Old 26th July 2002, 11:49   #4
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
PHP Code:
FileOpen $"file.txt" r
GetTempFileName $R0
FileOpen 
$1 $R0 w
loop
:
   
FileRead $$2
   IfErrors done
   StrCmp 
$"line to replace$\r$\n" +3
      FileWrite 
$"replacement of line$\r$\n"
      
Goto loop
   FileWrite 
$$2
   Goto loop

done
:
   
FileClose $0
   FileClose 
$1
   Delete 
"file.txt"
   
CopyFiles /SILENT $R0 "file.txt"
   
Delete $R0 

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 26th July 2002, 17:23   #5
Morphie
Junior Member
 
Join Date: May 2001
Location: Somewhere, I'm not sure...
Posts: 9
Send a message via ICQ to Morphie Send a message via AIM to Morphie Send a message via Yahoo to Morphie
THAT one helps! Thanks!
Morphie is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

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