//1安裝包目錄 NSBundle * bundle=[NSBundle mainBundle]; NSString *path=[bundle bundlePath]; NSFileManager * fm=[NSFileManager defaultManager]; NSError * error=nil; //2列出全部文件 NSArray *allFiles=[fm contentsOfDirectoryAtPath:path error:&error]; if (error!=nil) { NSLog(@"error:%@",error.description); }else{ NSLog(@"allFiles:%@",allFiles); } //找出全部圖片文件 NSMutableArray *imageFiles=[NSMutableArray array]; [allFiles enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { NSString * file=(NSString *) obj; if ([[file pathExtension] isEqualToString:@"png"]) { [imageFiles addObject:file]; } } ]; //寫入文件 NSArray* documents=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString * document=documents[0]; //存放路徑 NSString* plistFilePath= [document stringByAppendingPathComponent:@"images.plist"]; NSLog(@"plistFilePath=%@",plistFilePath); [imageFiles writeToFile:plistFilePath atomically:YES];