开发者

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

开发者 https://www.devze.com 2023-03-09 22:15 出处:网络
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..

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

精彩评论

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