- Home /
Please Help! I cannot delete my temp files on iPhone device. I get Unauthorized Access Exception.,Please help. I cannot delete temp files on iphone! UNAUTHORIZEDACCESSEXCEPTION
Hello, I have searched the forums and read where people have said to include "/private" in the path. I have done this but this is not working for me. Here is the code... (I have also tried it with the "/private" in the if exists path as well. Still does not work)
if UNITY_IPHONE
if (Directory.Exists(Application.persistentDataPath + "/" + filenameToDelete))
System.IO.File.Delete("/private" + Application.persistentDataPath + "/" + filenameToDelete);
...
Xcode says this....
UnauthorizedAccessException: /private/var/mobile/Containers/Data/Application/E5035393-08CD-486E-82D5-3A4CB2A06462/Documents/BoogityBoogity is a directory at System.IO.File.Delete (System.String path) [0x00000] in :0 at Pause.deleteGhostFiles () [0x00000] in :0 at Pause.Retry () [0x00000] in :0 at UnityEngine.Events.UnityAction.Invoke () [0x00000] in :0 at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in :0 at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in :0
...
One of the issues is on iOS you can't delete directories if they have files in them. Also there are separate commands for deleting directories and files. Once I understood this, I was able to rewrite and get it to work. Although I wish it were like other systems that allowed you do delete a parent directory and all dirs and files underneath. Really a pain this way.
Your answer
Follow this Question
Related Questions
Read and Write to text file Online 4 Answers
android browse and read text files 1 Answer
downloading file, saving on android 1 Answer
Android: Writing persistent data to SD Card 2 Answers
Stuck on MoveFileOrDirectory 2 Answers