## WriteFile / WriteFileIf / WriteFileStart / WriteFileEnd

`WriteFile` (clip, string filename, string expression1, ... , string expression16, bool "append", bool "flush")
`WriteFileIf` (clip, string filename, string expression1, ... , string expression16, bool "append", bool "flush")
`WriteFileStart` (clip, string filename, string expression1, ... , string expression16, bool "append")
`WriteFileEnd` (clip, string filename, string expression1, ... , string expression16, bool "append")

`WriteFile` evaluates expressionN, converts the result to a string and puts the result into a file.

The "run-time" variable current_frame is set so that you can use it in an "expression"
(this works similar as with ScriptClip, look there in the docu for more infos).
current_frame is set to -1 when the script is loaded and to -2 when the script is closed.

`WriteFile` generates output each frame, `WriteFileIf` generates output only if the first expression is `true`, there is no output at script opening or closure.
`WriteFileStart` and `WriteFileEnd` generates output only on script opening and closure, there is no action on each frame.

When append = `true`, the result will be appended on any existing file.
When flush = `true`, the file is closed and reopened after each operation so you can see the result immidiately (this may be slower).
For `WriteFileStart` and `WriteFileEnd` flush is always `true`.
The default for append is always `true`, except for `WriteFileStart` (here it is `false`).

#### This is best explained with some simple examples:

    filename = "c:\myprojects\output.txt"
    # create a test video to get frames
    Version()

    # the expression here is only a variable, which is evaluated and put in the file
    # you will get a file with the framenumber in each line
    WriteFile(filename, "current_frame")

    # this line is written when the script is opened
    WriteFileStart(filename, """ "This is the header" """)

    # and this when the script is closed
    WriteFileEnd(filename, """ "Now the script was closed" """)

Look how you can use triple-quotes to type a string in a string!

If the expression cannot be evaluated, the error message is written instead.
In case this happens with the If-expression in `WriteFileIf` the result is assumed to be `true`.

    # will result in "I don't know what "this" means"
    WriteFile(filename, "this is nonsense")

#### There are easier ways to write numbers in a file, BUT:

... with this example you can see how to use the "runtime functions" together with FrameEvaluate:

    # create a test video to get different frames
    Version.FadeIn(50).ConvertToYV12

    # this will print the frame number, a ":" and the average luma for that frame
    colon = ": "
    WriteFile("F:\text.log", "current_frame", "colon", "AverageLuma")

Or maybe you want the actual time printed too:

    # create a test video to get different frames
    Version.FadeIn(50).ConvertToYV12

    # this will print the frame number, the current time and the average luma for that frame
    # the triple quotes are necessary to put quotes inside a string
    WriteFile(last, filename, "current_frame", """ time(" %H:%M:%S") """, "AverageLuma")

#### More examples:

In `WriteFileIf` the FIRST expression is expected to be boolean (true or false).
Only if it is TRUE the other expressions are evaluated and the line is printed.
(Remember: && is AND, || is OR, == is EQUAL, != is NOT EQUAL)
That way you can ommit lines completely from your file.

    # create a test video to get different frames
    Version.FadeIn(50).ConvertToYV12

    # this will print the frame number, but only of frames where AverageLuma is between 30 and 60
    WriteFileIf(last, filename, "(AverageLuma>30) && (AverageLuma<60)", "current_frame", """ ":" """, "AverageLuma")

`$Date: 2005/10/03 16:31:31 $`