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 Guy-Corbett · Mar 01, 2015 at 05:09 PM · androidwwwdeletedirectorysharing

Sharing violation when deleting a directory used by a WWW object

If I load a local file using unity's www class, then later try to delete the folder containing that file, I get an exception. Here's the full explanation.

I have some code which attempts to sync some files from the internet to the local disk. The files are then used by the app and, images in particular, are loaded loaded using the www class by declaring it like this; new WWW(@"file://" + imageFilePath). However, later the user might want to resync those files, in which case I was deleting the directory which contained them by calling Directory.Delete(outDirPath, true), to delete the directory and all the files it contains so I could then create the directory and start from scratch.

This all works fine on windows but on android attempting to delete the directory throws an exception saying that there was a sharing violation on the path. I tracked this down to the www objects - if I never create any accessing that directory, deleting it doesn't throw the exception. So to try and fix this I first made sure that I didn't have any www objects hanging around in memory which could potentially be keeping a lock on the files they loaded but the exception still got thrown.

Currently I'm working around this by not deleting the directory, just the files it contains, by calling;

 foreach(var file in Directory.GetFiles(outDirPath))
 {
   File.Delete(file);
 }

Which works fine even when I have created www objects but worries me as it suggests there really is something I'm not clearing up which still has a lock on the directory. Has anyone else encountered this?

Comment
Add comment · Show 2
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 ♦ · Mar 01, 2015 at 01:55 PM 0
Share

This is not a good idea on Android as a lot of people have limited Data downloads. They don't want to be repeatedly downloading more data that is potentially already on the device - Just some advice.

avatar image Guy-Corbett · Mar 01, 2015 at 02:07 PM 0
Share

Fair point, however I show warnings about downloads which are going to be of any reasonable size. Also ideally this would be a tablet app I'm developing - where most of the time a connection to the internet means wifi. Personally though I find it annoying when apps warn me about data use, though I readily admit I maybe unusual in that respect. Still the average smart phone is full of apps that don't warn the user; Facebook, Instagram etc.

However, this specific issue doesn't look like it's related to actually downloading as it only occurs when I use www object to load a local file and then after try to delete the directory containing it. I imagine it's just coincidence that the local file in this case was downloaded from the internet.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get file list from a directory on Android 4 Answers

Share image on selected media 1 Answer

Android Internet not connecting 1 Answer

Any way around WWW timeout on Android? 2 Answers

Android Exception getInputStream() is not available 0 Answers


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