• 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
createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists


  • Subject: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
  • From: Andreas Grosam <email@hidden>
  • Date: Mon, 29 Oct 2012 10:22:57 +0100

I'm attempting to create a directory with NSFileManager's method. The directory may already exist.

According the documentation <https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html> the method shall return YES if the directory already exists:

"
Return Value
YES if the directory was created or already exists or NO if an error occurred.
"

However, when the directory already exists it returns NO with error parameter set:


           NSFileManager* fm = [[NSFileManager alloc] init];
           NSString* tmpDir = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Test"];
           NSError* error;
           if (![fm createDirectoryAtPath:tmpDir
              withIntermediateDirectories:NO
                               attributes:nil
                                    error:&error]) {
               NSLog(@"ERROR: setup test environment with error: %@", error);
           }



Console:

ERROR: setup test environment with error: Error Domain=NSCocoaErrorDomain Code=516 "The file “Test” couldn’t be saved in the folder “T” because a file with the same name already exists." UserInfo=0x100600150 {NSFilePath=/var/folders/m9/5p__qm3967qchc9_26tl85km0000gn/T/Test, NSUnderlyingError=0x100602d00 "The operation couldn’t be completed. File exists"}


Do I miss something?


OS X 10.7.5

Regards
Andreas
_______________________________________________

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: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
      • From: Sean McBride <email@hidden>
    • Re: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: zlib, objective-zip, NSDataCategory
  • Next by Date: More NSFileManager Issues
  • Previous by thread: Re: zlib, objective-zip, NSDataCategory
  • Next by thread: Re: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
  • Index(es):
    • Date
    • Thread