The Write to file can be used to write text to a specific file. The file will be cleared first before writing the text.
This image shows an example on how this can be used. This example will write the log text to the test.txt file. While writing to the file it will substitude the date state and the time state with the correct values so the log will show the actual date and time.
This action does clears the file each time so using this for a log may not be the best thing. Lets continue with the append to file action.
The Append to file can be used to write text to a specific file. The file will NOT be cleared first before writing the text. So this means the text is put right at the end of the file.
This image shows an example on how this can be used. This example will write the log text about the last received Twitch chat message to the test.txt file. While writing to the file it will substitude the date state, the time state and both Twitch states with the correct values.
Since this is the append action we probably need to add a newline in front or at the end to ensure the log is put on a new line in the file and not right behind the last character. It all depends of course on want you need.
The Create file can be used to create a file. Be careful using this as it will overwrite existing files. You can use Values and such in your file name or path to make it as dynamic as you want.
The Delete file can be used to delete a file from your disc. Be careful using this as it will be removed and it cannot be recovered.
The File contents to Custom State can be used to set the text of a file to a custom state in Touch Portal. This action will get the full content of the file and stores it into a custom state you have set up.
This action will be very handy if you have software for which Touch Portal does not have an integration yet but is capable of saving output to a file.
With the when-file-changes event, you can listen to when a file changes its contents and with this action you can then right away store that value to a state and use it within Touch Portal. Lets take a look at this event in the next section.
The Get File line count to Value action can be used to get the amount of lines and store it in a Value. You can use this in other parts of your flow.
The Get line from File to Value action can be used to get the n-th line from a text file and store it in a Value.
The When file changes event can be used to listen to a file for when its contents are changed. This usually happens when somebody updates the file and saves it.
In this example we listen to a change in the file test.txt and when it is changed we read the contents and save it in a state.
This events listens to the file object. This means that when you load it in some application and write it it, this will not trigger. Only when the user saves the file in said application will this trigger because then the file will actually be written to.
Also keep in minds that some operations will trigger the event multiple times such as a function that clears the file and saves it and then puts the text in the file and saves it again.