• 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
Can't create temporary file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can't create temporary file


  • Subject: Can't create temporary file
  • From: Rick Mann <email@hidden>
  • Date: Sat, 14 May 2011 01:46:46 -0400

OS X 10.6.7.

I'm trying to create a temporary file as part of exporting some app data. But I get this error when I try to create the file. The error code is ridiculously unhelpful:

2011-05-13 22:27:32.074 Foo[35181:a0f] Error creating file [file://localhost/private/var/folders/0O/0O9Zc+ZKFCy+BtbYF754gk+++TI/-Tmp-/TemporaryItems/(A Document Being Saved By Foo 2)/Bar.osm.tmp]: Error Domain=NSCocoaErrorDomain Code=2 UserInfo=0x2002b90c0 "The operation couldn’t be completed. (Cocoa error 2.)"


Here's the code up until the creation of the file:

- (void)
exportBarToURL: (NSURL*) inURL
{
    NSLog(@"Exporting bar file to: %@", inURL);

    //  Create a temporary file into which to build the bar file…

    NSFileManager* fm = [NSFileManager defaultManager];

    NSError* err = nil;
    NSURL* tempDir = [fm URLForDirectory: NSItemReplacementDirectory
                            inDomain: NSUserDomainMask
                            appropriateForURL: inURL
                            create: true
                            error: &err];
    if (err != nil)
    {
        NSLog(@"Error creating temporary directory for URL %@: %@", inURL, err);
        return;
    }

    NSString* tempFilename = [inURL.lastPathComponent stringByAppendingPathExtension: @"tmp"];
    NSURL* tempFile = [tempDir URLByAppendingPathComponent: tempFilename];

    //  Delete the temporary file, if it exists…

    [fm removeItemAtURL: tempFile error: nil];

    //  Create the file…

    NSFileHandle* file = [NSFileHandle fileHandleForWritingToURL: tempFile error: &err];
    if (err != nil)
    {
        NSLog(@"Error creating file [%@]: %@", tempFile, err);
        return;
    }
    ...
}

Any idea what I'm doing wrong?

TIA,
Rick

_______________________________________________

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 create temporary file
      • From: Fritz Anderson <email@hidden>
    • Re: Can't create temporary file
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Temporary directory names?
  • Next by Date: Re: @property IBOutlet
  • Previous by thread: Re: Temporary directory names?
  • Next by thread: Re: Can't create temporary file
  • Index(es):
    • Date
    • Thread