views:

34

answers:

1

i want to create a folder in our app local directories ...

the file structure i want to create will look like current date year/month/date the root directory of this structure is year inside that current month inside that current date folders ..

this way i hav to create the folders...

any help appreciated...

+1  A: 

this is a straight forward task.
First you have to split the date into components.

NSDate *date = [NSDate date];
NSUInteger dateFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [[NSCalendar currentCalendar] components:dateFlags fromDate:date];
NSInteger year = [components year];
NSInteger month = [components month];
NSInteger day = [components day];

Then create the path you want to create.

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *dir = [NSString stringWithFormat:@"%d/%d/%d", year, month, day];
NSString *path = [documentsDirectory stringByAppendingPathComponent:dir];

and finally, create the directory

NSError *error;
if (![[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:0 error:&error])
    NSLog(@"Error creating path %@ [%@]", path, error);
fluchtpunkt
i want to print also the particular weekday for that date....like sunday or monday...
lak in iphone
you can get the weekday out of NSDateComponents too. add the corresponding constant to dateFlags, I think it's NSWeekDayCalendarUnit. but not sure, I'm on my ipad now,far away from the mac. and if this is in your flags use [components weekDay] to get the number. then use a switch statement or an array to get a weekday string from the weekdaynumber. Just have a look at NSDateComponents documentation to see the real values, it's a good read anyway.
fluchtpunkt
thanks for that reply,and i want to add my string to file and save it as name.html and then add this file to created path
lak in iphone