WebDev Get File/Folder Resource Structure

Ignition 8.1.2, Linux AMI EC2

I’m using the WebDev as a repo for process documentation files. I’m using Tree components in views for users to be able to browse the files and open, based on selected equipment. What I would like to be able to do is utilize a scripting function to browse the current directory structure and convert that to a JSON structure to update the tree “items” property to without having to manually add items to the tree as new documents/folders are uploaded in the designer.

Basically, I’m looking for how to get to

https://<gateway>/system/webdev/<project>/<path to equipment folder>

via scripting. I can build the element tree or whatever easily enough from that point. I thought about browsing the gateway file structure, but I’m hoping there is a cleaner way.

Mounted folders are ‘dumb’ - they don’t actually know what they contain, they just attempt to retrieve whatever path you give them. You’d have to deliberately browse the filesystem via a separate gateway-scoped script to ‘know’ what is contained in a directory.

java.nio.file.Files.walk is the most idiomatic/modern way to walk a directory in Java, and is almost guaranteed to be more performant than any Jython builtin method.

1 Like

Thanks Paul. The only way I could figure to do the job with Jython was with import os based stuff and a gateway message handler, and I knew there had to be a better way.
With the Java method linked, would I not still have to resort to using a gateway scoped script and browse the file system, or am I missing something?

Nope, you’re not missing anything. You could set up something like a file system watcher, in a persistent background thread…but that’s probably overkill (though, I don’t know what your needs actually are). I’d just do a slow background poll and cache the results somewhere, i.e. a document tag/system.util.getGlobals().