0
回答
app bundle与sandbox 目录文件拷贝
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

这儿有段代码,教大家如何拷贝文件。

 

- (void) copySampleFilesToMyDocumentsFolder {
	NSError *error;
	NSFileManager *fileManager = [NSFileManager defaultManager];
	
	NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
	
	NSArray *dirContents = [fileManager contentsOfDirectoryAtPath: bundleRoot error: &error];
	NSArray *onlyPdf = [dirContents filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @"self ENDSWITH '.jpg'"]];
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDir = [paths objectAtIndex: 0];
	
	for (int i = 0; i < onlyPdf.count; i++) {
		NSString *pdfName = [onlyPdf objectAtIndex: i];
		
		NSString *docPdfFilePath = [documentsDir stringByAppendingPathComponent: pdfName];
		
		//Using NSFileManager we can perform many file system operations.
		BOOL success = [fileManager fileExistsAtPath: docPdfFilePath];
		
		if (!success) {
			NSString *samplePdfFile  = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: pdfName];
			
			success = [fileManager copyItemAtPath: samplePdfFile toPath: docPdfFilePath error: &error];
			
			if (!success){}
				//              NSAssert1(0, @"Failed to copy file '%@'.", [error localizedDescription]);
				//debugLog(@"Failed to copy %@ file, error %@", pdfName, [error localizedDescription]);
			else {
				//debugLog(@"File copied %@ OK", pdfName);
			}
		}
		else {
			//debugLog(@"File exits %@, skip copy", pdfName);
		}
	}
}
 


原文链接:http://blog.csdn.net/favormm/article/details/6550883
<无标签>
举报
长平狐
发帖于5年前 0回/120阅
顶部