This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory error:&error]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *path; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectory"]; | |
path = [path stringByAppendingPathComponent:@"SomeFileName"]; | |
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *path; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectory"]; | |
path = [path stringByAppendingPathComponent:@"SomeFileName"]; | |
NSError *error; | |
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does file exist? | |
{ | |
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) //Delete it | |
{ | |
NSLog(@"Delete file error: %@", error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *path; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"]; | |
NSError *error; | |
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does directory exist? | |
{ | |
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) //Delete it | |
{ | |
NSLog(@"Delete directory error: %@", error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *path; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"]; | |
NSError *error; | |
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) //Does directory already exist? | |
{ | |
if (![[NSFileManager defaultManager] createDirectoryAtPath:path | |
withIntermediateDirectories:NO | |
attributes:nil | |
error:&error]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSData *file; | |
file = ... | |
NSString *path; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SomeDirectoryName"]; | |
path = [path stringByAppendingPathComponent:@"SomeFileName"]; | |
[[NSFileManager defaultManager] createFileAtPath:path | |
contents:FileData | |
attributes:nil]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *path; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"My Directory"]; | |
path = [path stringByAppendingPathComponent:@"My Filename"]; | |
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) | |
{ | |
//File exists | |
NSData *file1 = [[NSData alloc] initWithContentsOfFile:path]; | |
if (file1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[NSFileManager defaultManager] moveItemAtPath:MySourcePath toPath:MyDestPath error:nil]; |
OlderNewer