Question

i have a bit frustated problem here, The problem is I want to copy a directory from Bundle into Library path in my app, but the code can't do that. The tree of the directory is showing here :

enter image description here

before I copy the directory, i wanna check the directory contents in bundle, but the array return 0 item. The code i use is this :

NSString * templatesBundlePath = [[NSBundle mainBundle] pathForResource:@"Templates" ofType:nil];
NSArray * packFolders = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:[NSURL fileURLWithPath:templatesBundlePath] includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLIsDirectoryKey, nil] options:0 error:&error];

the packfolders contain 0 item.

and if the contain is not 0 I try to copy it with this code :

NSString * templatesAppPath = NSApplicationSupportDirectoryPath(@"Templates");
[[NSFileManager defaultManager] copyItemAtPath:templatesBundlePath toPath:templatesAppPath error:&error];

when i try to check the bundle directory size with this code

NSFileManager *fm = [[NSFileManager alloc] init];

resultSize = [[[fm attributesOfItemAtPath:[[NSURL fileURLWithPath:templatesBundlePath]  path] error:nil] objectForKey:NSFileSize] unsignedIntegerValue];

NSLog(@"Size: %lu", (unsigned long)resultSize);

the value only show 68, but the real size in finder is 200MB

is there somebody who has a problem like mine? can somebody help me?

thank you

Was it helpful?

Solution

The project folders are yellow, which means that they are groups and not folders. The directory structure will be removed on bundling the resource with the app and all the files are placed in the root of you bundle.

Just remove all the groups from your project and drag the folders back into you project, now select create folders instead of groups.

enter image description here

OTHER TIPS

Please try this to get black.jpg image path :

NSString *strpath=[NSString stringWithFormat:@"%@",[[NSBundle mainBundle]pathForResource:@"Templates" ofType:@""]]; strpath=[strpath stringByAppendingString:@"/"]; strpath=[strpath stringByAppendingString:@"80s"]; strpath=[strpath stringByAppendingString:@"/"]; strpath=[strpath stringByAppendingString:@"80s_a-team"]; strpath=[strpath stringByAppendingString:@"/"]; strpath=[strpath stringByAppendingString:@"black"]; strpath =[strpath stringByAppendingString:@".jpg"];

Try following Code

  NSArray *libraryPath=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        NSString *directoryPath = [libraryPath objectAtIndex:0];
         NSString *imagePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Templete"];

                // Copy the image Folder from the package to the users filesystem
                [fileManager copyItemAtPath:imagePathFromApp toPath:directoryPath error:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top