- Home /
How can I access an external folder in the WebGL build of my app?
In my standalone app, I get the names of files in a folder that is located in the same place as the executable using Directory.GetFiles(). How can the same thing be achieved in a WebGL build if I put the folder in the same place as the index.html?
I've tried using the WWW class, but I think it can only retrieve information about individual files, not folders. I need to get information about the folder, since I don't know what the names of the files or quantity of files will be. Basically, I want to be able to iterate through the contents of the folder, using the filenames and later loading the files. WebGL is pretty challenging to debug, but the WWW object seems to be null when given the url of a folder since in Debug.Log all of the properties of the object print out as blank:
WWW www = new WWW(Application.dataPath + "/myDir");
yield return www;
I've also tried using mapPath() the way it is used in an answer I found to a similar question: Answer regarding mapPath
It is supposed to map the virtual path to a physical directory that can be passed in to Directory.GetFiles(), but that is throwing a null reference error.
Answer by mvm95 · Apr 02, 2017 at 09:55 AM
Well, the only solution I've found is in the comments on the only answer to a similar question: Less than ideal solution
Basically, since the WWW class can get individual files, the workaround was to create a text file that contains the names of all the files in the directory. Any time a user adds a file to the directory, they will also have to update the text file, and then the information loaded from the text file (each file name) can be used to get each file in the directory. I hope somebody finds a better way, so users don't have to remember to update the text file, which could result in typos that end up excluding files.
Your answer
Follow this Question
Related Questions
How to stream a image or text in webGL? 0 Answers
Is there a way to load images into a WebGL app? 2 Answers
WWW class on WebGL: URL is wrong 1 Answer
Load image from url in Webplayer 1 Answer