Skip to content

Instantly share code, notes, and snippets.

@yeahq
yeahq / gist:2391666
Created April 15, 2012 10:05
Show contents of Documents directory
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]);
@yeahq
yeahq / gist:2391659
Created April 15, 2012 10:04
Downloding zip and extracting in main bundle subdirectory at runtime
//http://stackoverflow.com/questions/5385480/iphone-downloding-zip-and-extracting-in-main-bundle-subdirectory-at-runtime
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"];
ZipArchive *zipArchive = [[ZipArchive alloc] init];
[zipArchive UnzipOpenFile:filepath Password:@"xxxxxx"];
[zipArchive UnzipFileTo:{pathToDirectory} overWrite:YES];
[zipArchive UnzipCloseFile];
[zipArchive release];
@yeahq
yeahq / gist:2391656
Created April 15, 2012 10:03
How to copy a file from resources to documents?
// From: http://stackoverflow.com/questions/4743317/iphone-how-to-copy-a-file-from-resources-to-documents
NSFileManager *fmngr = [[NSFileManager alloc] init];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mydb.sqlite" ofType:nil];
NSError *error;
if(![fmngr copyItemAtPath:filePath toPath:[NSString stringWithFormat:@"%@/Documents/mydb.sqlite", NSHomeDirectory()] error:&error]) {
// handle the error
NSLog(@"Error creating the database: %@", [error description]);
}
[fmngr release];