Is a directory

Discussion in 'Mac Programming' started by Miglu, Mar 4, 2011.

  1. Miglu macrumors member

    Joined:
    Jan 22, 2010
    #1
    I am trying to save an array:
    Code:
    -(IBAction)save:(id)sender{
    	NSSavePanel* savePanel = [NSSavePanel savePanel];
    	if (NSFileHandlingPanelCancelButton != [savePanel runModal]) {
    		NSURL* url = [savePanel directoryURL];
    		NSFileManager* manager = [NSFileManager defaultManager];
    		if(![manager createFileAtPath:[url path] contents:[NSData dataWithBytes:array length:sizeof(*array)] attributes:nil]){
    			NSLog(@"Error was code: %d - message: %s", errno, strerror(errno));
    
    		}
    	}
    }
    
    This is logged: "Error was code: 21 - message: Is a directory." What is the problem?
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    Your path is pointing to a directory instead of a file?

    B
     
  3. Miglu thread starter macrumors member

    Joined:
    Jan 22, 2010
    #3
    But is createFileAtPath not supposed to create a file inside a directory?
     
  4. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
  5. Miglu thread starter macrumors member

    Joined:
    Jan 22, 2010
    #5
    Alright, the path has to end in the file's name.
     

Share This Page