Skip to content

Instantly share code, notes, and snippets.

@weekwood
Created January 16, 2014 08:46
Show Gist options
  • Save weekwood/8451702 to your computer and use it in GitHub Desktop.
Save weekwood/8451702 to your computer and use it in GitHub Desktop.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"templates"];
NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"templates"];
if (![fileManager fileExistsAtPath:documentDBFolderPath]) {
//Create Directory!
[fileManager createDirectoryAtPath:documentDBFolderPath withIntermediateDirectories:NO attributes:nil error:&error];
} else {
}
NSArray *fileList = [fileManager contentsOfDirectoryAtPath:resourceDBFolderPath error:&error];
for (NSString *s in fileList) {
NSString *newFilePath = [documentDBFolderPath stringByAppendingPathComponent:s];
NSString *oldFilePath = [resourceDBFolderPath stringByAppendingPathComponent:s];
if (![fileManager fileExistsAtPath:newFilePath]) {
//File does not exist, copy it
[fileManager copyItemAtPath:oldFilePath toPath:newFilePath error:&error];
if([s isEqualToString:@"catalog.yml"]){
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *data = [fileManager contentsAtPath:[NSString stringWithFormat:@"%@/catalog.yml",documentDBFolderPath]];
NSError *err;
id yaml = [YAMLSerialization YAMLWithData:data options:kYAMLReadOptionStringScalars error:&err];
NSString *filePath = [documentDBFolderPath
stringByAppendingPathComponent:@"catalog.plist"];
[yaml writeToFile:filePath atomically:YES];
}
} else {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment