Skip to content
⌘ NSIS Forum Archive

Read file and write to another file

5 posts

r2du-soft#

Read file and write to another file

hi
i read a text file and write that test file strings to a variable

Unicode True

!include "CharToASCII.nsh"
!include "Base64.nsh"

!include x64.nsh

Var X

Section

ClearErrors
FileOpen $4 "C:\A.txt" r
Read_Try:
IfErrors Read_Try_Closed
FileReadUTF16LE $4 $5
StrCpy $X $X$5
Goto Read_Try
Read_Try_Closed:
FileClose $4
MessageBox MB_Ok "$X"
;----------------------------
ClearErrors
FileOpen $4 "C:\B.txt" w
IfErrors done
FileWriteUTF16LE $4 "$0"
FileClose $4
done:

SectionEnd
But the A.txt file is large...
also i use the: nsis-3.03-strlen_8192.zip file but my string is larger than 8192 bytes
now i need read the all of the text file string in variable,how can do this?


is second question i want know is possible read a exe file informations with FileOpen in variable and after that create empty a exe file and write that variable string (exe bytes) to empty exe file ?
i do this work with FileOpen but after write in the new empty exe file,that exe file not runned!
r2du-soft#
Read file and write to another file

hi
i read a text file and write that test file strings to a variable

Unicode True

!include "CharToASCII.nsh"
!include "Base64.nsh"

!include x64.nsh

Var X

Section

ClearErrors
FileOpen $4 "C:\A.txt" r
Read_Try:
IfErrors Read_Try_Closed
FileReadUTF16LE $4 $5
StrCpy $X $X$5
Goto Read_Try
Read_Try_Closed:
FileClose $4
MessageBox MB_Ok "$X"
;----------------------------
ClearErrors
FileOpen $4 "C:\B.txt" w
IfErrors done
FileWriteUTF16LE $4 "$0"
FileClose $4
done:

SectionEnd
But the A.txt file is large...
also i use the: nsis-3.03-strlen_8192.zip file but my string is larger than 8192 bytes
now i need read the all of the text file string in variable,how can do this?


is second question i want know is possible read a exe file informations with FileOpen in variable and after that create empty a exe file and write that variable string (exe bytes) to empty exe file ?
i do this work with FileOpen but after write in the new empty exe file,that exe file not runned!
Anders#
If you want to go past the NSIS string limit then you must do all the work yourself with the system plug-in, you cannot use the built-in instructions like StrCpy. You could probably do it line by line if no single line is longer than the limit.

To read/write .exe and other binary files you must read/write single bytes, you cannot parse them as text.
r2du-soft#
i search about system plug-in
but just see this sample..



but i tested that and not give result
Anders#
A normal text editor that supports large files will use a file mapping, it will not put the entire thing in memory all at once. If you need that or not depends on how large it actually is. You cannot expect that every system will be able to allocate hundreds of megabytes in a continuous buffer.