x


Before updating to Windows 10 you may need to return your Pro license. More information here

delete file on IOS

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

more ▼

asked Oct 10, 2012 at 10:58 PM

avatar image

madpoet0204
18 8 11 12

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Oct 10, 2012 at 11:41 PM

avatar image

kmeboe
1.5k 7 14 20

Awesome, will give it a whirl..:)

Oct 10, 2012 at 11:56 PM madpoet0204

Yay! It worked! Thx a bunch kmeboe!

System.IO.File.Delete("/private" + Application.persistentDataPath+"/"+filename);

Oct 11, 2012 at 01:26 PM madpoet0204

You're welcome! Glad I could help.

Oct 11, 2012 at 03:22 PM kmeboe

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'

Feb 20, 2013 at 06:33 AM petrapparent

I honestly don't remember how I stumbled upon this particular idiosyncrasy. But I'm happy to hear that it's working for people!

Feb 22, 2013 at 09:55 PM kmeboe
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x195
x70
x33

asked: Oct 10, 2012 at 10:58 PM

Seen: 4305 times

Last Updated: Feb 22, 2013 at 09:55 PM