# Get File Path with WebDev

**URL:** <https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021>\
**Category:** Ignition\
**Created:** [July 27, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021 "2023-07-27T15:26:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [July 27, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021/1 "2023-07-27T15:26:45Z")

</div>

I am trying to iterate through a mounted folder and find a specific file. The file has multiple folders inside of that folder and then has the specific pdf file that I want to open. In the end want to open in pdf viewer in ignition. Is there any way to either return the json of the mounted folder where I can then iterate and set path or something similar?

---

<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:** [July 27, 2023, 3:28pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021/2 "2023-07-27T15:28:38Z")

</div>

No. Mounted folders work on "just-in-time" discovery - when a request is made for file X, a request is made for folder Y/file X, right then. There's no indexing or crawling or anything of your filesystem done by Ignition.

If you want more capability, you'll have to script it yourself using a Python endpoint.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [July 27, 2023, 3:46pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021/3 "2023-07-27T15:46:00Z")

</div>

I am ok with scripting but I don't know the best approach for that. Would I need to have a layout of all my files and then use that?

---

<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:** [July 27, 2023, 4:07pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021/4 "2023-07-27T16:07:46Z")

</div>

Start by hardcoding the directory you care about into your Python endpoint.  
Then, you could pay attention to the `remainingPath` request parameter in a Python endpoint:  
[https://docs.inductiveautomation.com/display/DOC81/Web+Dev#WebDev-PythonResources](https://docs.inductiveautomation.com/display/DOC81/Web+Dev#WebDev-PythonResources)

If it's None, then this is a request to the 'root', so you're going to use Java's File class to list the child files in that directory:  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html#listFiles()](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html#listFiles())  
And assemble that into a JSON payload or whatever else.

If there _is_ a remaining path, then you're going to try to find that file, [load the file](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/FileInputStream.html), and then [write it](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStream.html#transferTo(java.io.OutputStream)) to the [request's output stream](https://docs.oracle.com/javaee/7/api/javax/servlet/ServletResponse.html#getOutputStream--).

# Be careful with file traversal! A malicious actor could pass a relative path like `../../../../etc/passwd` to your endpoint!

To avoid this risk, I'd suggest taking advantage of our [`SecurePathUtils`](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.30/com/inductiveautomation/ignition/client/launch/util/SecurePathUtils.html) class.

---

<div class="post-metadata">

**Author:** ![Grace\_Tarler](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Grace\_Tarler](https://forum.inductiveautomation.com/u/Grace_Tarler)\
**Post date:** [July 27, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021/5 "2023-07-27T17:43:01Z")

</div>

Could you describe a little more about the directory that I need to hard code. I am very new to this part of ignition so a bit confused. There are a lot of paths so would I have to list all those paths out?

---

<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:** [July 27, 2023, 5:54pm UTC](https://forum.inductiveautomation.com/t/get-file-path-with-webdev/77021/6 "2023-07-27T17:54:15Z")

</div>

You currently have a mounted folder, right? The path to hardcode is whatever path you currently have in that mounted folder. That's the "root directory", as far as the rest of the handler is concerned. Your browse operation to list files will be relative to that directory. It's up to you whether to support multiple layers of nesting, or just a flat browse of files at that directory.
