4b. Working with files: read a text file

In the BrainVoyager QX scripting editor, it is possible to read from and write to files. This can be useful for writing logfiles when a script is running or inspecting certain values from files.

 

The procedure is the following.

At first, which is not necessary, a dialog is created for presenting the information to the user of the script.

Accordingly a file object is created. This is done by indicating the path name and the file name when using the "new File" command.

The file is opened in the read only mode. It is read line by line, so that is known how many lines there are in the file; the line counter performs this task. (This is also not necessary, but if the file is large it might be convenient to adjust the dialog).

The text that is gathered from the file object is communicated to a text label that is part of the dialog.

Finally the dialog with the text from the file is shown by the "exec()" command.

 

When executing the script, and choosing a stimulus protocol (*.prt), the following dialog shows the text that was read by the script:

 

Next: 4c: Working with files (continued)
Index