- Home /
Using WWW to load all files in StreamingAssets directory
Is it possible to use WWW to load any and all files in a given directory within StreamingAssets, or do I have to know the explicit name of every file I'm looking to load?
For examaple, "StreamingAssets/" contains a list of .xml files of arbitrary file names "dataSet01.xml", "saveFile-3.xml", "character_data_set_17.xml", so on, and I need to load them all at runtime.
Answer by Julien-Lynge · Jun 10, 2013 at 11:47 PM
This isn't really a WWW question. There isn't any way to download all files from a directory regardless of the technology. What you need is some way to get a directory listing.
Where is StreamingAssets located? Are you trying to load from the local disk or from a folder in a web directory? If from local disk, look for ways to get directory listings with C# (it's not Unity-specific). If it's remote, you have to make the directory accessible, and that has to be done in Apache or whatever you're running (and it's different for HTTP vs FTP).
The directory listing seems to be my answer here. I'll set up a known file with a listing of all the other files to load.
I'm using the builtin "Strea$$anonymous$$gAssets" directory provided by Unity due to the fact that it gives me a multi-platform location where I can store and replace files outside of the editor. The main use of WWW is due to the fact that the directory is compressed on Android and i believe iOS, so I can't use .net's IO classes to access the files.
Thanks for the response!
Did you got any solution, me too need to implement this one of my game which made in WebGL, I couldn't access Strea$$anonymous$$gAssets when uploading the file in L$$anonymous$$S Server. Including WWW class also not giving the expected result.
Hi,
Access Strea$$anonymous$$gAssets path folder using WWW class
public string filePath = Application.strea$$anonymous$$gAssetsPath + "/UserDetails.xml";
public string result = "";
void Awake ()
{
filePath = Application.strea$$anonymous$$gAssetsPath + "/UserDetails.xml";
}
void Start ()
{
StartCoroutine(userDetailsXmlPath() );
}
IEnumerator userDetailsXmlPath()
{
print (filePath);
if (filePath.Contains ("://") || filePath.Contains (":///")) {
WWW www = new WWW (filePath);
yield return www;
result = www.text;
print (result);
FetchUserDetails ();
} else {
result = File.ReadAllText (filePath);
print (result);
FetchUserDetails ();
}
}
public void FetchUserDetails()
{
XmlDocument userXml1 = new XmlDocument ();
userXml1.LoadXml(result);
XmlNodeList userList = userXml1.GetElementsByTagName ("user");
foreach(XmlNode userValue in userList)
{
XmlNodeList userContent = userValue.ChildNodes;
objUser = new Dictionary<string, string>();
foreach(XmlNode value in userContent)
{
objUser.Add (value.Name, value.InnerText);
}
userFullDetails.Add (objUser);
userCountInXml = userList.Count;
userId = new string[userList.Count];
questionSetOfUser = new string[userList.Count];
}
AssignUserXmlValuesToArray ();
}
Answer by Pallav-Nawani · Jun 23, 2018 at 06:10 AM
Alternatively, you could create a file called 'filelist.txt', which lists all the files you need to load. Then, first download filelist.txt, parse it, then download one by one all the files.
Your answer
Follow this Question
Related Questions
How to load an image at runtime via WWW correctly 1 Answer
Localy load XML data from StreamingAssets folder 0 Answers
[help]How can I read the file in StreamingAssets on iPad/iPhone platform??? 0 Answers
How to read xml file on Android using www and StreamingAssets? 2 Answers
Loading and playing AudioClip at runtime 2 Answers