- Home /
Delete file in iOS with Application.dataPath get UnauthorizedAccessException: Access to path is denied
Hello everyone, I'm having a little issue with deleting a file on iOS. Basically, I save all my file inside a "AssetBundles" folder then just drag and drop it in the "Data" folder when building the at. I have a file call "buildFlag.dat" to check if the app is just installed in order to clear the cache.
I was successful reading the file and clear the cache, but then when I try to delete the "buildFlag.dat" I got that exception. Does anyone have any idea how to get around this? Thanks in advance, and here is my code snippet:
 public void cleanCacheHelper(){
         string path = Application.dataPath + "/AssetBundles/buildFlag.dat";
         if (File.Exists(path))
         {
             string flag = File.ReadAllText(path);
             if(flag == "Clear")
             {
                 Debug.Log("-->>>> Clearing Cache <<<<--");
                 Caching.CleanCache();
                 #if (UNITY_IOS && !UNITY_EDITOR)
 
                 System.IO.File.Delete(Application.dataPath+"/AssetBundles/buildFlag.dat");
 
                 Debug.Log("Build Flag has been deleted");
                 #endif
             } else
             {
                 Debug.Log("-->>>> Not Clearing Cache <<<<--");
             }
         } else
         {
             Debug.Log("-->>>> Build Flag Does not exist not clearing cache<<<<--");
         }
     }
Here is the log I got: UnauthorizedAccessException: Access to the path "/private/var/mobile/Containers/Bundle/Application/695C517F-AF4C-4490-BE7A-830E32329F91/myapp.app/Data/AssetBundles/buildFlag.dat" is denied.
Try to use Long Path Tool, it really can help you with that. It will really help you to solve your problem. ,Hi, for problems concerning path too long issues, I suggest you try the new long path tool. This can help you with all kinds of path too long cases,
Answer by StuwuStudio · Mar 31, 2017 at 11:01 AM
I know, i'm a bit late but try Application.persistentDataPath instead of Application.dataPath
Your answer
 
 
             Follow this Question
Related Questions
Add unityARkit project with IOS project 1 Answer
Admob crashes game on initialize (IOS) 0 Answers
Unity4 deploying Unity5 player? 0 Answers
Pausing on iOS still using CPU 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                