好的,
所以我有一个 Cydia 应用程序需要更新。我知道 Cydia 应用程序没有文档文件夹,因此您必须创建一个。以下是我之前在 iOS 4 中的做法(在 iOS 5 上不起作用):
mkdir("/var/mobile/Library/APPNAME", 0755);
mkdir("/var/mobile/Library/APPNAME/Documents", 0755);
NSString *foofile = @"/var/mobile/Library/APPNAME/Documents/database.db";
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
if (fileExists == TRUE) {
NSLog(@"already exists");
} else {
NSLog(@"doesn't exists");
NSFileManager *fileManager = [[NSFileManager defaultManager]autorelease];
NSError *error;
NSString *documentDBFolderPath = @"/var/mobile/Library/APPNAME/Documents/database.db";
NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.db"];
[fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error];
}
我还包含了将数据库文件复制到该文件夹的代码。这不起作用(即使我通过 SSH 手动创建文件夹)。
求助!谢谢。
最佳答案
下面是我创建目录的方法
-(void)createDirectory:(NSString *)directoryName atFilePath:(NSString *)filePath
{
NSString *filePathAndDirectory = [filePath stringByAppendingPathComponent:directoryName];
NSError *error;
if (![[NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory
withIntermediateDirectories:NO
attributes:nil
error:&error])
{
NSLog(@"Create directory error: %@", error);
}
}
关于objective-c - 如何制作目录iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8030054/