How to use File Input & Output actions

Touch Portal Action Guides

This guide will explain the action category "File IO". Here is the list of all actions and events of the File IO category. Each action will be walked through on this page.

Action: Write to file

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.



Action: Append to file

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.



Action: Create file

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.



Please note that when you use Values and states in your filenames that you only use allowed filename characters. Especially important for time as a Value or state as they can contain characters that are not allowed in filenames. Consider using the Replace in Value action to remove any not allowed characters.


Action: Delete file

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.



Action: File contents to Custom State

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.



Action: Get Line Count from File into a Value

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.



Action: Get n-th Line from File into a Value

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.



Event: When file changes

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.




Back to Guide Overview