- Home /
How to write subfolders to PersistentDataPath iOS
So at runtime I need to be able to store downloaded data on the iOS device so I can use at later times. I want to keep things organized so I don't have to use a weird naming convention.
How can I create a subdirectory in Application.PersistentDataPath for iPhone?
I thought I could do something like this but I get a error through xcode saying it can't find the directory.
string path = Application.persistentDataPath +"/localData/" + character.Name + ".xml";
StreamWriter fileWriter = File.CreateText(path);
fileWriter.WriteLine("Hello world");
fileWriter.Close();
Debug.Log(File.ReadAllText(path));
Answer by Subliminalman · Feb 27, 2013 at 05:41 AM
Thanks danny but I a different way to do it and forgot to update this.
Here's what I did if anyone needs to know
DirectoryInfo dirInf = new DirectoryInfo(Application.persistentDataPath + "/" + "localPet"); if(!dirInf.Exists){ Debug.Log ("Creating subdirectory"); dirInf.Create();
}
Answer by dannyskim · Feb 26, 2013 at 05:25 PM
Try:
string path = Application.dataPath + "/Raw/" + fileName;
Please change your comment into an answer and mark it as the right one then.
Using slash (/) directly works, but consider using Path.Combine
ins$$anonymous$$d:
string subdir = Path.Combine(Application.persistentDataPath, "localData");
string filepath = Path.Combine(subdir, character.Name + ".xml");
Your answer
Follow this Question
Related Questions
Application.dataPath + "/Raw" not loading texture on iOS? 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Difference between Application.persistantDataPath Vs Application.dataPath 2 Answers
IOS cant move file from cache path 0 Answers
Elements of Canvas with Constant Physical Size doesn't show up in iOS Simulator 0 Answers