# Save string to a text file

**URL:** <https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771>\
**Category:** Ignition\
**Tags:** ignition81, scripting, docker\
**Created:** [January 19, 2023, 12:40am UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771 "2023-01-19T00:40:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![NII](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nii/32/12920_2.png) [@NII](https://forum.inductiveautomation.com/u/NII)\
**Post date:** [January 19, 2023, 12:40am UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/1 "2023-01-19T00:40:46Z")

</div>

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:

```auto
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' 🙄

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 19, 2023, 12:45am UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/2 "2023-01-19T00:45:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 19, 2023, 2:07am UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/3 "2023-01-19T02:07:23Z")

</div>

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:**

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

```

---

<div class="post-metadata">

**Author:** ![NII](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nii/32/12920_2.png) [@NII](https://forum.inductiveautomation.com/u/NII)\
**Post date:** [January 19, 2023, 2:37am UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/4 "2023-01-19T02:37:30Z")

</div>

Apparently _system.file.saveFile_ causes error.

 ![WrapperLog1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/c/ecb330aaba383e35e28470c51ad8278a79b36749.jpeg)

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

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

```

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [January 19, 2023, 2:07pm UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/5 "2023-01-19T14:07:57Z")

</div>

Looks like you've got it sorted, so that is good. I'll mention that [system.file.saveFile](https://docs.inductiveautomation.com/display/DOC81/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()`.

---

<div class="post-metadata">

**Author:** ![Ken\_Moldt](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@Ken\_Moldt](https://forum.inductiveautomation.com/u/Ken_Moldt)\
**Post date:** [June 16, 2023, 4:56pm UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/6 "2023-06-16T16:56:38Z")

</div>

I don't like resurrecting and old post, but I'd like to keep the thread going for someone else walking this path.

I'm attempting to do something similar. I'm running in a container, and I'd like to pull some blobs down from a database and save the files locally to allow source binds for things like images and audio files.

I get an error if I try something simple like

```auto
data = "Testing"
system.file.writeFile("test.txt", data)

```

If I give it a full path, I do not receive an error, but I never see the file. Something like

```auto
data = "Testing"
filename = "/usr/local/bin/ignition/test.txt"
system.file.writeFile("/usr/local/bin/ignition/test.txt", data)

```

I know I can pull the blob and get the file. This is just to prove out that I can save the file to the container in a persisted volume to allow access to perspective resources. I'm unsure if the path is relative to a location or starts at the root, but I haven't seen a difference in behavior when I try various approaches.

I'm sure someone else has solved this, but this is the only thread I have been able to find thus far. Any thoughts?

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [June 17, 2023, 11:42am UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/7 "2023-06-17T11:42:02Z")

</div>

Are you running this in Client/Designer or Gateway scope? You want to be in gateway scope for the file to end up in your container.

---

<div class="post-metadata">

**Author:** ![Ken\_Moldt](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@Ken\_Moldt](https://forum.inductiveautomation.com/u/Ken_Moldt)\
**Post date:** [June 19, 2023, 1:10pm UTC](https://forum.inductiveautomation.com/t/save-string-to-a-text-file/68771/8 "2023-06-19T13:10:07Z")

</div>

Hey Kevin. The script was written at the gateway, but I was calling it from a script console session on a client as a quick test. This was me just not thinking through the execution. Thanks for the quick response.
