objective-ccydia

How to make a directory iOS?


Okay,

So I have a Cydia app that I need to update. I am aware with Cydia apps that they don't have a Documents folder, so you have to make one. And here's how I made it before in iOS 4 (which doesn't work on 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];

}

I also included code that copies the database file to that folder, too. That doesn't work (even when I create the folder manually via SSH).

Please help! Thanks.


Solution

  • Here is the method I made to create directories

    -(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);
        }
    }