I'm trying to delete file on iOS. I've tried the following in C# script:
System.IO.File.Delete("file://" + Application.persistentDataPath+"/"+"SnapShot5.png");
I've also tried: File.Delete("SnapShot5.png");
That didn't work either. I have the using System.IO; in the first line of the script and checking File exists with: System.IO.File.Exists in the same script works, but not deleting line.
Any ideas? Thx
Answer by kmeboe
Oct 10, 2012 at 11:41 PM
Try changing your path to include "/private" at the beginning, like so:
string filePath4Realz = "/private" + oldFilePath
Also make sure you don't prepend with "file://".
I'm not sure why this works; it looks like iOS needs this at the beginning if you want to make changes to your files. Hopefully someone else can chime in to say if this is a horrible idea, but it works for me.
Edit: you will of course want to conditionally add this to your path if you're on iOS. You don't want to do this with the unity player. Something like "#if UNITY_IPHONE" should work fine.
Awesome, will give it a whirl..:)
Yay! It worked! Thx a bunch kmeboe!
System.IO.File.Delete("/private" + Application.persistentDataPath+"/"+filename);
You're welcome! Glad I could help.
Major kudos to kmeboe, it works. Absolutely no idea how you knew about the "/private" prepend. I bow in awe. Google has no trace of this 'feature'
I honestly don't remember how I stumbled upon this particular idiosyncrasy. But I'm happy to hear that it's working for people!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
11 People are following this question.
Can I get a folder up hierarchy relative to the dataPath?
Open an HTML file from streamingAssets - Android
How can i remove Texture on the screen
File.Delete problems with Application.CaptureScreenshot