#2596 Accessing Resource Files from within the Pod

jhughes Thu 2 Mar 2017

I have some files put into resDirs and when I run the main class from F4, I have no problems accessing these with a relative file path File(`rsc/image'). When this ran directly from the pod fan, it can't resolve the files anymore.

How do you access files in the pod when the code is run from the pod? Haven't been able to find anything in the docs explaining accessing compiled resources.

brian Thu 2 Mar 2017

Typically you use sys::Pod.file:

fansh> pod := Pod.find("testSys")
fansh> pod.file(`/res/test.txt`)

You can also use "fan://" URI scheme:

fansh> `fan://testSys/res/test.txt`.get as File

jhughes Fri 3 Mar 2017

I tested the first method byt putting this directly into the code and calling the main class from the command prompt to test running from the compiled pod:

pod := Pod.find("podName")

This works fine but i'm not sure if this is the most efficient way to access files located in the pod running the code in the first place. This means to access files in a resource compiled in a pod, I have to call that pod running the code to load at runtime to access the files located in the same pod the code is running from instead of having a relative path where they are accessible directly from the code. If this is as intended, I can make it work as I just did but I wanted to make sure it's not just the working solution but also the intended and efficient way to access files from within the same pod as your running code.

brian Fri 3 Mar 2017

Not sure I understand your concern, but if its how to get the pod of the running code, then you can use typeof.pod for the pod of current class.

jhughes Fri 3 Mar 2017

My concern was having to call the pod back into itself via the Pod.find method and naming the pod i'm already in by name, just opens up chances for user error. typeof.pod is a much more elegant solution for what i'm trying to do.


fraya Fri 3 Mar 2017

You can use Foo#.pod.file for short

Login or Signup to reply.