Save string to a text file

I am running ignition in a docker container, when I save a string to a text file, what folder does it save to?

Below is the code, right of the doc:

data = "Some text here"
filename = system.file.saveFile("MyTextFile.txt")
if filename is not None:
   system.file.writeFile(filename, data)

I can't find 'MyTextFile.txt' :roll_eyes:

Likely /usr/local/bin/ignition/ in the container. That's wouldn't be preserved with the normal volume options, but you should be able to enter the container while running to check.

You probably should make your folder path explicit.

I do this sort of thing all of the time, but I never use the saveFile method; system.file.writeFile is enough. Also, I typically specify a third argument, that identifies whether or not I want to append or overwrite in the event that the file already exists. Overwrite is probably the default, but when assembling a file from a blob or something of that nature, the third argument allows this to happen.

Here is an example that could be easily adapted for your usage case:

path = 'C:/Users/YOURUSERNAME/Desktop/MyTextFile.txt'	
data = "Some text here"
system.file.writeFile(path, data, False)

Apparently system.file.saveFile causes error.

I end up using below, this works and it's preserved

data = "My other text"
system.file.writeFile("/user-data/MyTextFile.txt", data)

Looks like you've got it sorted, so that is good. I'll mention that system.file.saveFile is only available in [Vision] Client scope since it prompts the user with a save dialog. In gateway scope, you've got to specify the path directly to writeFile().