From 22a11ecf1a6745050767eaea0f5aed26a44eb762 Mon Sep 17 00:00:00 2001 From: gcasa Date: Mon, 27 Oct 2008 00:54:29 +0000 Subject: [PATCH] * Headers/Foundation/NSFileManager.h: Added declaration for new method here. * Source/NSFileManager.m: Added implementation for the method -(BOOL)createDirectoryAtPath:withIntermediateDirectories:attributes: error:. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26971 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++ Headers/Foundation/NSFileManager.h | 4 +++ Source/NSFileManager.m | 40 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/ChangeLog b/ChangeLog index bc062a0eb..057bc9c50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-26 20:59-EDT Gregory John Casamento + + * Headers/Foundation/NSFileManager.h: Added declaration for new method + here. + * Source/NSFileManager.m: Added implementation for the method + -(BOOL)createDirectoryAtPath:withIntermediateDirectories:attributes: + error:. + 2008-10-19 Wolfgang Lux * configure.ac: fix test for sychronization in objc runtime. diff --git a/Headers/Foundation/NSFileManager.h b/Headers/Foundation/NSFileManager.h index 2439c0be0..9cc7eb5f3 100644 --- a/Headers/Foundation/NSFileManager.h +++ b/Headers/Foundation/NSFileManager.h @@ -206,6 +206,10 @@ extern "C" { - (BOOL) copyPath: (NSString*)source toPath: (NSString*)destination handler: (id)handler; +- (BOOL) createDirectoryAtPath: (NSString *)path + withIntermediateDirectories: (BOOL)flag + attributes: (NSDictionary *)attributes + error: (NSError **) error; - (BOOL) createDirectoryAtPath: (NSString*)path attributes: (NSDictionary*)attributes; - (BOOL) createFileAtPath: (NSString*)path diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index fd9ee7592..7fa847a90 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -670,6 +670,46 @@ static NSStringEncoding defaultEncoding; } } +/** + * Creates a new directory and all intermediate directories + * if flag is YES, creates only the last directory in the path + * if flag is NO. The directory is created with the attributes + * specified in attributes and any error is returned in error.
+ * returns YES on success, NO on failure. + */ +- (BOOL) createDirectoryAtPath: (NSString *)path + withIntermediateDirectories: (BOOL)flag + attributes: (NSDictionary *)attributes + error: (NSError **) error +{ + BOOL result = NO; + if(flag == YES) + { + NSEnumerator *paths = [[path pathComponents] objectEnumerator]; + NSString *path = nil; + NSString *dir = [NSString string]; + + while((path = (NSString *)[paths nextObject]) != nil) + { + dir = [dir stringByAppendingPathComponent: path]; + result = [self createDirectoryAtPath: dir + attributes: attributes]; + } + } + else + { + NSString *dir = [path lastPathComponent]; + result = [self createDirectoryAtPath: dir + attributes: attributes]; + } + + if(error != NULL) + { + *error = [NSError _last]; + } + return result; +} + /** * Creates a new directory, and sets its attributes as specified.
* Creates other directories in the path as necessary.