开发者

Count the number of files inside a folder in Objective C (Cocoa)

I m making an array of images animate like a flicker book animation,i m storing these images inside a folder which intern resides inside Resource folder of my pr开发者_运维技巧oject in xcode.. these images will vary,that is why i have to determine the exact number of images inside the folder so how should i determine this? is there any API in cocoa to achieve this?


Try

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

For more info, http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html


First, you need to access the bundle path of your application:

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

Now append your folder name to the bundlePath

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜