"resource" syntax

Hi, I successfully embedded a resource for opening a file in the root directory, however it failed when placed in a subdir

new_resource(“www/index.html”) Works ok when compiling and uplinking

however

f = open(“resource://www/index.html”,‘rb’) fails

if you omit “www/” from both statements everything works ok

What is the correct syntax for opening the resource.

Thanks in advance
Alex

Well, I found out myself. Just in case someone else bumps into this please see my findings.

You can’t do it nicely, but there is way if you use unique names all over your project.

When you add resources Zerynth apparently ignores the folder and adds just the filename to the resource table. So you need to specify only the filename when opening the resource for reading.

e.g:

new_resource(“www/tst.txt”) # contains “Zerynth Rocks!”
new_resource(“tst.txt”) #contains “This is a surprise!”

ff = open(“resource://tst.txt”)

print("resource content: ", ff.read(100))

print(“Done!”)

the above code shields:

resource content: Zerynth Rocks!

Done!

If instead you change the order of the resource declaration…

new_resource(“tst.txt”) #contains “This is a surprise!”
new_resource(“www/tst.txt”) # contains “Zerynth Rocks!”

ff = open(“resource://tst.txt”)

print("resource content: ", ff.read(100))

print(“Done!”)

Now you get:

resource content: This is a surprise!

Done!

As you can see the first filename match is the resource you’ll open.

So just make sure all your resources have different names!

PS: Would be great to make a note in the docs such that others don’t trip on this behavior wondering why they can’t open folder resources.

Best regards
Alex