# Prompt User to Select Folder

**URL:** <https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [December 18, 2024, 10:31pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012 "2024-12-18T22:31:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [December 18, 2024, 10:31pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/1 "2024-12-18T22:31:49Z")

</div>

How can I use a popup similar to `system.file.openFile()` to prompt the user to select a folder (directory) where files will be written?

---

<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:** [December 18, 2024, 10:36pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/2 "2024-12-18T22:36:48Z")

</div>

`system.file.saveFile`?

> **[system.file.saveFile | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-file/system-file-saveFile)**
>
> Prompts the user to save a new file named filename.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 18, 2024, 10:47pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/3 "2024-12-18T22:47:23Z")

</div>

Unless the nuance was to allow a directory _to be selected_, which we don't have a convenient helper for; you'll have to do some scripting.

Something like:

> [@Save selected files to a selected path keeping the original name](https://forum.inductiveautomation.com/t/save-selected-files-to-a-selected-path-keeping-the-original-name/68787/3):
>
> There's no system.file.saveDirectory function, so choosing a directory to save to gets a bit complicated. Once you have the directory, you should be able to use system.file.writeFile with a generated directory + filename path, and system.file.readFileAsBytes to read the source file(s), as needed. Choosing a directory with a GUI would look something like this: from javax.swing import JFileChooser fileChooser = JFileChooser() fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES\_ONLY result…

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [December 19, 2024, 2:42pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/4 "2024-12-19T14:42:51Z")

</div>

I have an XML tree that I made with `xml.etree.ElementTree`. Usually I'd use `tkinter` and `tree.write` to prompt for the directory location and save the file.

How would I go about doing something similar in Ignition?

---

<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:** [December 19, 2024, 2:46pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/5 "2024-12-19T14:46:51Z")

</div>

I think you need to follow Paul's advice/post, it seems `system.file.saveFile` will only let the user point to a _file_, not a directory.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [December 19, 2024, 2:59pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/6 "2024-12-19T14:59:42Z")

</div>

Thanks. The `JFileChooser` is exactly what I needed

> [@Save selected files to a selected path keeping the original name](https://forum.inductiveautomation.com/t/save-selected-files-to-a-selected-path-keeping-the-original-name/68787/3):
>
> There's no system.file.saveDirectory function, so choosing a directory to save to gets a bit complicated. Once you have the directory, you should be able to use system.file.writeFile with a generated directory + filename path, and system.file.readFileAsBytes to read the source file(s), as needed. Choosing a directory with a GUI would look something like this: from javax.swing import JFileChooser fileChooser = JFileChooser() fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES\_ONLY result…

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [December 19, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/7 "2024-12-19T15:10:35Z")

</div>

I get a permission denied error when I try to write the file. I'm not trying to do it anywhere restricted, just `user\documents`

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [December 20, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/8 "2024-12-20T19:40:14Z")

</div>

My user has permissions for the folder. How can I troubleshoot this issue?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 20, 2024, 10:53pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/9 "2024-12-20T22:53:48Z")

</div>

Are you sure the path is exactly what you think it is? Any chance Windows file separators are getting mixed up somewhere, so you think you're writing to `Users\Documents` but you're actually attempting to implicitly create a `Users/Documents` folder, for instance? Are the paths fully qualified?

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [December 30, 2024, 2:37pm UTC](https://forum.inductiveautomation.com/t/prompt-user-to-select-folder/100012/10 "2024-12-30T14:37:03Z")

</div>

That's definitely it. I had accidentally use the file I'm trying to write instead of the directory path that I had the user select in my string format for the path.

```python
ET.ElementTree(program).write('{}\program.xml'.format(program), encoding='utf-8', xml_declaration=True)

```

instead of

```python
ET.ElementTree(program).write('{}\program.xml'.format(directoryPath), encoding='utf-8', xml_declaration=True)

```
