On Feb 23, 2013, at 9:57 AM, John Joyce wrote:

> A bit of trouble with the NSFileManager docs for the methods:
> – createDirectoryAtURL:withIntermediateDirectories:attributes:error:
> – createDirectoryAtPath:withIntermediateDirectories:attributes:error:
> 
> Both say:
> 
> Return Value
> YES if the directory was created or already exists or NO if an error occurred.
> 
> Both say: 
> 
> createIntermediates (the BOOL argument)
> If YES, this method creates any non-existent parent directories as part of 
> creating the directory in url. If NO, this method fails if any of the 
> intermediate parent directories does not exist.
> 
> 
> Both fail to indicate CLEARLY that the BOOL argument to 
> withIntermediateDirectories must be YES or the to return value to be YES if 
> the directory already exists.
> Setting argument withIntermediateDirectories to NO causes a return value of 
> NO and an error to be generated. 
> 
> The docs do not seem clear on this. (not to me anyway).
> If the directory you are creating is also considered an "intermediate parent" 
> directory, that is just confusing.
> 
> Can anybody explain to me how this makes any sense?
> My workaround while using createIntermediates as NO was to check the error 
> code and userInfo.
> But setting createIntermediates to YES gives no error if the directory exists.

This probably doesn't explain anything, but these semantics match the 
difference between the commands "mkdir" and "mkdir -p".

When given a path where any of the intermediate directories doesn't exist or 
where the final directory does exist, "mkdir" will fail.  It's the "strict" 
version which does only and exactly what was requested (creating a directory at 
a specific path) and no more (doesn't create intermediate directories).

"mkdir -p" is the relaxed version which means, more or less, "just make sure 
there's a directory at this path, no matter which directories you do or don't 
need to create".

Regards,
Ken


_______________________________________________

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

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

Reply via email to