Archive: Possible Bug in File Handling


Possible Bug in File Handling
  This Code deletes the content of the File test1.txt if it existed before. I noticed this because of a typo in one of my scripts. Tested with v.2.45 on Vista SP2 64Bit and XP SP3


Outfile test.exe

>Var File1
>Var File2
RequestExecutionLevel user
Section "Main"
SetOutPath "EXEDIR"
FileOpen "$File1" "$EXEDIR\test1.txt" w
StrCpy "$File2" "$EXEDIR\test2.txt"
FileWrite "$File2" "Hello World"
FileClose "$File1"
>SectionEnd
>
Why is the File test1.txt altered? FileWrite is referring to the wrong handle.

Why is the File test1.txt altered?
The file is altered because your script contains this line
FileOpen "$File1" "$EXEDIR\test1.txt" w
The Users Manual explains why this happens:
4.9.5.2 FileOpen
user_var(handle output) filename openmode
... The openmode should be one of "r" (read) "w" (write, all contents of file are destroyed) or "a" (append, meaning opened for both read and write, contents preserved).