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.

I know, i’m a bit late but try Application.persistentDataPath instead of Application.dataPath

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,