Count the number of files inside an Objective-C folder (Cocoa)

I make the array of images animated, like an animation of a flicker book, and save these images inside the folder that is inside the project resources folder of my project in xcode .. these images will change, so I have to determine the exact number of images inside the folder, since I have to to determine? is there any cocoa API to achieve this?

+7
source share
2 answers

First you need to access the package path of your application:

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

Now add your folder name in bundlePath

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

Try

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

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

+15
source

All Articles