Automation Action – Read Or Write Text File | ThinkAutomation
Automation Action: Read Or Write Text File
Save data to a text file or read an existing text file and assign the content to a variable.
Saves data to any text file and/or reads the contents of the file into a variable. This action can be used to save text or %variables% to a text file, or read the contents of a text file and assign the contents to a %variable%.
The File Path must contain a path & filename of the text file to write to/read from.
Writing
On the Write To File tab you can define the text that you want to write to the file. The file will be created if it does not already exist. All directories contained in the path will be created if they do not exist.
Select the file Format. This can be ASCII, Unicode or UTF-8 (default). Select the Line Terminator that will be appended to the text written to the file.
Enter the Content that you want to write to the file. This can contain %variable% replacements.
If the Append To File option is enabled then the new text will be added to the end of any existing text file. If the Make Backup option is enabled the existing file will be copied to the same file name with a .BAK file first.
On the Read From File tab you can select a ThinkAutomation variable that you want to assign the text file contents to. The file will be read again after any text is written to it.
Reading Only
Select the Read From File tab and then select the %variable% to assign the text file contents to from the Assign Content To list. You can optionally assign the total line count to a variable selected from the Assign Total Line Count To list.
You can optionally read specific lines only from the text file. In the Read From Line entry, specify the starting line number (or leave blank for the start of the file). This can be a %variable%. In the Read To Line entry, specify the end line number (or leave blank for the end of the file). This can be a %variable%. If both the Read From Line and Read To Line values are blank, then the entire file is read. When reading specific lines, the text file is not read into memory, making it suitable for large files.
If you need to read new lines from a text file, save the Assign Total Line Count value (you can use the Embedded Value Store action to persist the value between automation executions). Then on subsequent reads, set the Read From Line value to the previous line count + 1.
If nothing is specified in the Content entry then the file is only read.