问题
i want to get all the photos names saved in my documents folder .as it contains some resources other than images,i need to select the images itelf from the documents folder and populate the names of images in an array.
回答1:
NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDir error:nil];
NSArray *onlyPics = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.png'"]];
来源:https://stackoverflow.com/questions/7865544/how-to-get-all-the-names-of-photos-only-which-are-saved-in-documents-folder-of-i