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

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


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

On 29.10.2012, at 12:43, Mike Abdullah wrote:

>
> On 29 Oct 2012, at 09:22, Andreas Grosam <email@hidden> wrote:
>
>> 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?
>
> Is it possible you've ended up with a *file* there named "Test" rather than a directory?

This doesn't seem the case:
(note the folder's name is "RelaxTest")

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


Terminal:
$ pwd
/var/folders/m9/5p__qm3967qchc9_26tl85km0000gn/T
T$ ls  -al
total 816
drwx------  10 me  staff     340 29 Okt 13:15 .
drwxr-xr-x   5 me  staff     170 26 Okt 09:20 ..
drwxr-xr-x   2 me  staff      68 29 Okt 13:10 RelaxTest
...

T$ cd RelaxTest/
RelaxTest$ ls
RelaxTest$ ls -al
total 0
drwxr-xr-x   2 me  staff   68 29 Okt 13:10 .
drwx------  10 me  staff  340 29 Okt 13:15 ..




_______________________________________________

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: Vincent Habchi <email@hidden>
References: 
 >createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists (From: Andreas Grosam <email@hidden>)
 >Re: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists (From: Mike Abdullah <email@hidden>)

  • Prev by Date: Re: App rejection due to app-sandboxing invalid entitlement
  • Next by Date: Re: More NSFileManager Issues
  • Previous by thread: Re: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
  • Next by thread: Re: createDirectoryAtPath:withIntermediateDirectories:attributes:error: Returns NO when it exists
  • Index(es):
    • Date
    • Thread