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%20Document%20Being%20Saved%20By%20Foo%202)/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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to