• 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
Creating a file using NSURL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating a file using NSURL


  • Subject: Creating a file using NSURL
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 15 Feb 2012 22:18:30 -0800

Am I missing something obvious here?

I'm trying to create an empty file (prior to using a NSFileHandle to write its contents), and I have a URL for the place to create it, and I want to avoid path-based API where possible, and I'm targeting 10.6. The only URL-based file creation API I know of is in NSData (NSFileManager can create directories from a URL, not files AFAICT.)

If the file can't be created (e.g. I tried to create it on a DVD that happened to show up in the Save panel), -[NSData writeToURL:error:] correctly fails, but it returns an error that looks like this:

> Error Domain=NSCocoaErrorDomain Code=4 "The file “[…]” doesn’t exist." UserInfo=0x400f252c0 {NSFilePath=/Volumes/[…], NSUnderlyingError=0x400f25140 "The operation couldn’t be completed. No such file or directory"}

IOW, NSData is reporting the "wrong" error, as this message isn't helpful to present to the user.

Is there another API I should be using that will producing an error saying that the file couldn't be created -- or better still saying *why* the file couldn't be created? Does the misleading error message count as a bug in -[NSData writeToURL:error:]?




_______________________________________________

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: Creating a file using NSURL
      • From: Tomas Franzén <email@hidden>
  • Prev by Date: Re: ARC + return of autoreleased CFType
  • Next by Date: CGWarpMouseCursorPosition and large delta/offset at next mouse motion event
  • Previous by thread: Re: ARC + return of autoreleased CFType
  • Next by thread: Re: Creating a file using NSURL
  • Index(es):
    • Date
    • Thread