Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pajamajama · Feb 12, 2014 at 10:59 PM · savefileapplicationdeletepersistentdatapath

How to delete everything at Application.persistentDataPath?

I'm saving some files to Application.persistentDataPath and now I would like the ability to clear out everything I've saved there at once. What's a good way to go about that? Also is there anything else stored there automatically that I should be aware of, maybe something I wouldn't necessarily want to delete.

Thank you! Kevin

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Feb 19, 2015 at 11:10 PM 0
Share

If its an asset you want to destroy you can use DestroyImmediate

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by tapvanvn_unity · Nov 23, 2018 at 03:55 PM

I think you can use this.

  foreach (var directory in Directory.GetDirectories(Application.persistentDataPath))
                 {
                     DirectoryInfo data_dir = new DirectoryInfo(directory);
                     data_dir.Delete(true);
                 }
     
                 foreach (var file in Directory.GetFiles(Application.persistentDataPath))
                 {
                     FileInfo file_info = new FileInfo(file);
                     file_info.Delete();
                 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by HitPoint · Feb 19, 2015 at 11:09 PM

On my project I tried writing an editor script to delete the contents of persistentDataPath, like this:

 DirectoryInfo dataDir = new DirectoryInfo(Application.persistentDataPath);
 dataDir.Delete(true);

However, I got an IOException with a "Sharing violation" message. I think this is because another editor script has some file within persistentDataPath open, and so it cannot be deleted.

So, I think the only way to properly delete the persistent data path is to close Unity3D and then use your operating system to delete the folder. On MacOS, this is ~/Library/Application\ Support/vendor/title/ and on Windows it is a similar path under your AppData\LocalLow folder.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by EricSmalls · Aug 03, 2018 at 08:56 AM

You can try to create a new file directory Directory.CreateDirectory (Application.persistentDataPath + "FilesToDelete"); Save the files you need to delete into the newly created Folder, then use DirectoryInfo dataDir = new DirectoryInfo(Application.persistentDataPath + "/FilesToDelete"); dataDir.Delete(true);

Hope this helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mobile delete file with specific file extension 1 Answer

System.IO.File does not contain a definition for 'WriteAllLines' 1 Answer

How to constantly save game progress? 1 Answer

How i can save persistent data for each scene? 1 Answer

Save files for a game 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges