Re: create folders
Re: create folders
- Subject: Re: create folders
- From: Dan Wood <email@hidden>
- Date: Sun, 10 Nov 2002 21:24:48 -0800
And to handle the case when you want to create a bunch of subfolders,
here's a category method on NSFileManager that I like to use. It
basically walks the path that you give it, and checks to see if each
directory exists. If not, it creates it for you. Kind of useful.
- (BOOL) createDirectoriesAtPath:(NSString *)inPath
attributes:(NSDictionary *)inAttributes
{
NSArray *components = [inPath pathComponents];
int i;
BOOL result = YES;
for (i = 1 ; i <= [components count] ; i++ )
{
NSArray *subComponents = [components subarrayWithRange:
NSMakeRange(0,i)];
NSString *subPath = [NSString pathWithComponents:subComponents];
BOOL isDir;
BOOL exists = [[NSFileManager defaultManager]
fileExistsAtPath:subPath isDirectory:&isDir];
if (!exists)
{
result = [[NSFileManager defaultManager]
createDirectoryAtPath:subPath attributes:inAttributes];
if (!result)
{
return result;
}
}
}
return result;
}
On Sunday, November 10, 2002, at 08:33 PM, Vince DeMarco wrote:
On Sunday, November 10, 2002, at 07:44 AM, Luca Torella wrote:
Hi,
how can I create a folder from Cocoa? And how to know the path of
my
app?
look at the documentation for NSFileManager.
look at the documentation for this method
- (BOOL)createDirectoryAtPath:(NSString *)path
attributes:(NSDictionary *)attributes;
vince
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Dan Wood
Karelia Software, LLC
email@hidden
http://www.karelia.com/
Watson for Mac OS X:
http://www.karelia.com/watson/
The information contained in this message or any of its attachments may
be privileged and confidential and intended for the exclusive use of
the addressee(s). Any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.