In my application, when a user makes a purchase in the application, the application needs to download and unzip the zip file to the application’s document folder. The mail file is downloaded and can be unpacked. I use Objective Zip to unzip the archive. The problem is that when you try to create folder paths for each file, folders are never created, and there are no errors.
Here is sample code for the section where this happens:
// Create file manager NSFileManager *fileMgr = [NSFileManager defaultManager]; //Unzip NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; ZipFile *unzipFile = [[ZipFile alloc] initWithFileName:[applicationDocumentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",@"Mid America Oireachtas 2011"]] mode:ZipFileModeUnzip]; NSArray *infos= [unzipFile listFileInZipInfos]; for (FileInZipInfo *info in infos) { //NSLog(@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level); // Locate the file in the zip [unzipFile locateFileInZip:info.name]; // Expand the file in memory ZipReadStream *read= [unzipFile readCurrentFileInZip]; NSMutableData *data= [[NSMutableData alloc] initWithLength:info.length]; int bytesRead = [read readDataWithBuffer:data]; [read finishedReading]; NSString *appSupportFolder = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *pathfull = [appSupportFolder stringByAppendingPathComponent:info.name]; NSString *path = [[pathfull stringByDeletingLastPathComponent] copy]; NSError *errorw; NSRange range = [path rangeOfString:@"__MACOSX"]; if (range.location == NSNotFound) { NSLog(@"last: %@", [path lastPathComponent]); if ([fileMgr createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&errorw]) { NSLog(@"Create Folder: %@", path); NSLog(@"Directory Win: %@", errorw); if (![[pathfull pathExtension] isEqualToString:@""] && ![[[pathfull lastPathComponent] substringToIndex:1] isEqualToString:@"." ]) { [data writeToFile:pathfull atomically:NO]; } } else { //NSLog(@"Create Folder: %@", path); NSLog(@"Directroy Fail: %@", errorw); } } } [unzipFile close]; //delete zip // For error information NSError *error; if ([fileMgr removeItemAtPath:[applicationDocumentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",@"Mid America Oireachtas 2011"]] error:&error] == YES) { NSLog(@"File Deleted"); } //delete zip // For error information NSError *error; if ([fileMgr removeItemAtPath:[applicationDocumentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",@"My Zip"]] error:&error] == YES) { NSLog(@"File Deleted"); }
Here is the corresponding snippet of output from the log file:
2012-01-04 17:12:51.509 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/ 2012-01-04 17:12:51.510 WhatsMyStageOn[3232:15503] Directory Win: (null) 2012-01-04 17:12:51.510 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/Documents/Mid America Oireachtas 2011 2012-01-04 17:12:51.510 WhatsMyStageOn[3232:15503] Directory Win: (null) 2012-01-04 17:12:51.510 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/Documents 2012-01-04 17:12:51.510 WhatsMyStageOn[3232:15503] Directory Win: (null) 2012-01-04 17:12:51.511 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/Documents/__MACOSX 2012-01-04 17:12:51.511 WhatsMyStageOn[3232:15503] Directory Win: (null) 2012-01-04 17:12:51.511 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/Documents/__MACOSX/Mid America Oireachtas 2011 2012-01-04 17:12:51.511 WhatsMyStageOn[3232:15503] Directory Win: (null) 2012-01-04 17:12:51.511 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/Documents/Mid America Oireachtas 2011 2012-01-04 17:12:51.512 WhatsMyStageOn[3232:15503] Directory Win: (null) 2012-01-04 17:12:51.544 WhatsMyStageOn[3232:15503] Create Folder: /Users/Brandon/Library/Application Support/iPhone Simulator/5.0/Applications/436C2C49-D79B-4CDA-B0AA-15BB98F6F75E/WhatsMyStageOn.app/Documents/Mid America Oireachtas 2011/Attractions 2012-01-04 17:12:51.544 WhatsMyStageOn[3232:15503] Directory Win: (null)
Reading the NSFileManager documentation, this is what should be displayed in the log, but no folders are created.
EDIT: Fixed not using a problem with documents, still the same problem as evaluation before editing.
EDIT: Updated code for a working solution!