• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Can't delete file on device
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't delete file on device


  • Subject: Re: Can't delete file on device
  • From: Conrad Shultz <email@hidden>
  • Date: Tue, 27 Mar 2012 14:16:51 -0700

On 3/27/12 1:50 PM, Rick Mann wrote:
>
> On Mar 27, 2012, at 12:05 , Mike Abdullah wrote:
>
>> Show us some code.
>
>     NSURL* url = [NSURL URLWithString: ci.diskURI];
>     if ([fm fileExistsAtPath: url.absoluteString])
>     {
>         NSLog(@"File exists: %@", url.absoluteString);
>     }
>
>     NSError* err = nil;
>     [fm removeItemAtURL: url error: &err];
>     if (err != nil)
>     {
>         NSLog(@"Unable to delete file at %@: %@\n%@", url, err, err.userInfo);
>     }

As David already pointed out you should probably be using file URLs.

There are a couple other issues:

1) You shouldn't handle errors by testing (err != nil).  This might work
(since you initialized err to nil) assuming that removeItemAtURL: isn't
fiddling with err anyway, but it's not guaranteed.  The preferred
approach is to test the return value of removeItemAtURL: (it returns
BOOL for a reason!) and examine err iff the method returns NO.

2) Less likely, but still reasonably plausible since you are working
with cache files (which I imagine have other clearance mechanisms), is
that you are encountering a race condition.  It's possible that another
thread removed the file in the intervening time between your
fileExistsAtPath: and removeItemAtURL: calls.  This is a major reason
why it's usually not useful to to ask "can I delete a file?" but rather
to try "delete the file!" and handle any errors appropriately.


--
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Can't delete file on device
      • From: Rick Mann <email@hidden>
References: 
 >Can't delete file on device (From: Rick Mann <email@hidden>)
 >Re: Can't delete file on device (From: Mike Abdullah <email@hidden>)
 >Re: Can't delete file on device (From: Roland King <email@hidden>)
 >Re: Can't delete file on device (From: Rick Mann <email@hidden>)
 >Re: Can't delete file on device (From: Mike Abdullah <email@hidden>)
 >Re: Can't delete file on device (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: NSScrollView automatically changes scroller styles?
  • Next by Date: Re: Can't delete file on device
  • Previous by thread: Re: Can't delete file on device
  • Next by thread: Re: Can't delete file on device
  • Index(es):
    • Date
    • Thread