I am trying to get selected files from bundle resourcePath on application launch. I am able to get all the files at resource path but when i try to get files with name stored in BGImage.plist i get error "cocoa 260" (item not found at specified path).
But images are present at the path and I can get all the images by doing [fileManager copyItemAtPath:bundlePath toPath:BGImagePath error:nil];
code below doesnt work.. (reference : iPhone (iOS): copying files from main bundle to documents folder error )
NSString* BGImagePath =[[[AppDelegate applicationDocumentsDirectory]
URLByAppendingPathComponent:@"BGImages" isDirectory:YES]
path];
NSFileManager* fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSArray *folderContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:BGImagePath error:&error];
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSString *BundleImagePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"BGImages.plist"]; //has file names
bgImagesArray = [[NSArray arrayWithContentsOfFile:BundleImagePath] retain];
if (folderContents.count == 0) {
for (id obj in bgImagesArray) {
NSError* error;
if ([fileManager
copyItemAtPath:[bundlePath :obj]
toPath:[BGImagePath stringByAppendingPathComponent:obj]
error:&error])
NSLog(@" *-> %@", [bundlePath stringByAppendingPathComponent:obj]);
}
}
}
Is there any other elegant way to get specific files without storing names in plist?
NSError" object instead of "nil" into the error parameter of "copyItemAtPath", do you get an error returned to you? does bgImagesArray actually load with values? - Michael Dautermann