How can i get the count of the files in a folder? [duplicate]
How can i get the number of files in a folder on iOS?
NSFileManager *filemgr = [NSFileManager defaultManager];
NSArray *filelist= [filemgr directoryContentsAtPath: yourPath];
int count = [filelist count];
NSLog ("%i",count);
directoryContentsAtPath:
is deprecated.
If you want get files count of Documents folder.
try to this.
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSArray *filelist= [fm contentsOfDirectoryAtPath:[docPaths objectAtIndex:0] error:nil];
int filesCount = [filelist count];
NSLog(@"filesCount:%d", filesCount);
- (NSArray *)directoryContentsAtPath:(NSString *)path
is deprecated. Use - (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error
instead. This would mean that Matt S's code from above would become:
NSFileManager * filemgr = [NSFileManager defaultManager];
NSArray * filelist = [filemgr directoryContentsAtPath:yourPath error:nil];
int count = [filelist count];
NSLog("%d", count);
NSArray* files = [[NSFileManager defaultManager] directoryContentsAtPath:DIRECTORY];
NSLog(@"%d",[files count]);
精彩评论