# system.file.writeFile | IOError: Unable to create path to file

**URL:** <https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083>\
**Category:** Ignition\
**Created:** [November 30, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083 "2022-11-30T13:12:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottmwyant](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/scottmwyant/32/66369_2.png) [@scottmwyant](https://forum.inductiveautomation.com/u/scottmwyant)\
**Post date:** [November 30, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/1 "2022-11-30T13:12:15Z")

</div>

I swear I've done this before but I can't find my code snippet...

I'm getting an IO error and having a heck of a time debugging it. The Ignition service is running as 'Local System' so permissions should not be an issue.

My code is `system.file.writeFile("C:\\foo.txt", "bar")`. I have tried single forward slash, etc. I don't know where to look to get more feedback. Running this in the script console (in read/write mode) or invoking a project script both results in:

```auto
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File"<module:sandbox>", line 6, in testWriteFile
IOError: Unable to create path to file 'C:\foo.txt'

```

I've also tried supplying more arguments... `system.file.writeFile("C:\foo.txt", "bar", False, "UTF-8" )`, nothing is giving me any different results.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 30, 2022, 1:14pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/2 "2022-11-30T13:14:38Z")

</div>

I think you need to be an admin to make a folder on the root of the C:\ drive so I don't think that just a regular local user is sufficient but instead would require the user to be admin. What happens if it tries making a folder inside `C:\Users\TheLocalUserAccount\SmapleFolder\sampleFile.txt`?

Also, the service is local system so that is what your gateway is running the script as. But if you're running this in script console, you are running it as whatever user you are logged in as. This does lead to some confusion (it's happened to me before) where things work in a gateway message handler but not in a script console or vice versa depending on your permissions.

---

<div class="post-metadata">

**Author:** ![scottmwyant](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/scottmwyant/32/66369_2.png) [@scottmwyant](https://forum.inductiveautomation.com/u/scottmwyant)\
**Post date:** [November 30, 2022, 1:23pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/3 "2022-11-30T13:23:50Z")

</div>

> [@bkarabinchak.psi](#):
>
> ...if you're running this in script console, you are running it as whatever user you are logged in as.

Ah, okay. Didn't know that. Tested that same line triggered by a button click from a perspective page and it worked! Thank you!!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 30, 2022, 1:25pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/4 "2022-11-30T13:25:26Z")

</div>

Not just as the user you are logged in as, but _on the machine that is running the Designer_ as well.

---

<div class="post-metadata">

**Author:** ![scottmwyant](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/scottmwyant/32/66369_2.png) [@scottmwyant](https://forum.inductiveautomation.com/u/scottmwyant)\
**Post date:** [November 30, 2022, 1:28pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/5 "2022-11-30T13:28:28Z")

</div>

So (on Windows) `%USERDOMAIN%/%COMPUTERNAME%/%USERNAME%` would need proper permissions for it to work from the script console; do I have that right?

Or rather, `%USERDOMAIN%/%USERNAME%`?

I'm not understanding the possible implications of the client machine being used. Would probably be a good thing to keep in mind.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 30, 2022, 1:35pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/6 "2022-11-30T13:35:49Z")

</div>

I'm not sure about the permissions stuff, but the main implication is that you could be running the Designer anywhere, so instead of writing to `C:\\foo.txt` on the Gateway, it's writing to `C:\\foo.txt` on whatever computer the Designer is running on.

---

<div class="post-metadata">

**Author:** ![scottmwyant](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/scottmwyant/32/66369_2.png) [@scottmwyant](https://forum.inductiveautomation.com/u/scottmwyant)\
**Post date:** [November 30, 2022, 1:43pm UTC](https://forum.inductiveautomation.com/t/system-file-writefile-ioerror-unable-to-create-path-to-file/67083/7 "2022-11-30T13:43:51Z")

</div>

> [@Kevin.Herron](#):
>
> ...it's writing to `C:\\foo.txt` on whatever computer the Designer is running on.

Oooh! Yes, confirmed. My designer is connected to a remote gateway. The real file path I was using wouldn't make sense for the Windows environment on my laptop. I changed the path to (the literal equivalent of) `%USERPROFILE%\Downloads` and no doubt, it ran successfully from script console and created a file on my machine.

Thanks @Kevin.Herron!
