Simple write text to file: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:Afrow UK|Afrow UK]] ([[{{ns:3}}:Afrow UK|talk]], [[{{ns:-1}}:Contributions/Afrow UK|contrib]])</small>
|}
<br style="clear:both;">
== Description ==
== Description ==
This is a simple function to write a piece of text to a file.
This is a simple function to write a piece of text to a file.
Line 34: Line 38:
!define WriteToFile "!insertmacro WriteToFile"
!define WriteToFile "!insertmacro WriteToFile"
</highlight-nsis> -Stu
</highlight-nsis> -Stu
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 03:03, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

This is a simple function to write a piece of text to a file. This will write to the end always.

== Usage ==

Push "hello$\r$\n" ;text to write to file 
Push "$INSTDIR\log.txt" ;file to write to 
Call WriteToFile

== Usage 2 ==

${WriteToFile} "hello$\r$\n" "$INSTDIR\log.txt"

The Function

Function WriteToFile
 Exch $0 ;file to write to
 Exch
 Exch $1 ;text to write
 
  FileOpen $0 $0 a #open file
   FileSeek $0 0 END #go to end
   FileWrite $0 $1 #write to file
  FileClose $0
 
 Pop $1
 Pop $0
FunctionEnd
 
!macro WriteToFile String File
 Push "${String}"
 Push "${File}"
  Call WriteToFile
!macroend
!define WriteToFile "!insertmacro WriteToFile"

-Stu