- Home /
Question by
ChuckSaldana · Feb 10, 2011 at 09:33 PM ·
iphonepathfile-io
iPhone System.IO.File.Exists() not working
The following instruction checks if the file at path exists:
string path = GetiPhoneDocumentsPath();
if (System.IO.File.Exists(path) == false) XmlTextWriter textWriter = new XmlTextWriter(path,null);
Then if the file does not exists it creates a new one, it all works well in unity execution, but when I execute the program in iphone, the file is never created.
Here's the function to obtain the path:
public static string GetiPhoneDocumentsPath () {
// Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
// Application.dataPath returns
// /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
// Strip "/Data" from path
string path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
// Strip application name
path = path.Substring(0, path.LastIndexOf('/'));
return path + "/Documents/myFile.xml";
}
Comment
I'm pretty sure you have to use 'Application.persistentDataPath' by the way...
Best Answer
Answer by ChuckSaldana · Feb 11, 2011 at 12:50 AM
Got it!
FileInfo info = new FileInfo(path);
if (info == null || info.Exists == false) { ... };
Your answer
Follow this Question
Related Questions
Is there a method for getting application saved data off the iPhone? 2 Answers
Saving File in new directory - Unauthorized Access Exception 1 Answer
How can I put a mp3 in the iphone documents folder then load it with www? 1 Answer
capture the screenshot to iPhone photo gallery 2 Answers
fileio System.Xml 2 Answers