资源的子文件夹中的文件数

时间:2012-05-09 08:28:47

标签: objective-c

我要知道我的Resources文件夹的每个子文件夹中有多少图像。我发现了这个:

NSMutableString* bundlePath = [NSMutableString stringWithCapacity:4];
[bundlePath appendString:[[NSBundle mainBundle] bundlePath]];

[bundlePath appendString:@"/MyFolder"];
NSArray *directoryContent  = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundlePath error:nil];
int numberOfFileInFolder = [directoryContent  count];

和此:

int pants = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/your/path/here" error:NIL] count];

最好的方法是什么?

解决方案:

int numberOfFileInFolder = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"/Angry"] error:Nil] count];

复制文件时要注意!!!不要忘记选中“为任何添加的文件夹创建文件夹引用”

0 个答案:

没有答案
相关问题