Search code examples
iphoneobjective-cnsfilemanager

Count Number of Files with Extension in iPhone Documents


I can think of ways to do this with taking the array:

NSArray *doc_contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];

and doing string parsing to find the extension, but that seems like a roundabout way of doing this. Is there a cut and dry way to count the number of .jpg files in my iPhone app documents directory?

Thanks.

EDIT Solved here: Creating an array from documentsDirectory includes ends with .MOV


Solution

  • Both of these links are great resources for this problem.

    This one deals with the situation when you have multiple file extensions you are looking for:
    NSPredicate endswith multiple files

    This one is focused on just one extension:
    Creating an array from documentsDirectory includes ends with .MOV

    Both methods use the NSPredicate class.