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

> 
> On 29 Oct 2012, at 09:22, Andreas Grosam <[email protected]> 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 protected])

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

This email sent to [email protected]

Reply via email to