Lets say you want to remove(delete) all the files of a particular extension say PNG from the Documents folder of the app. We can use the following code snippet.


NSString *fileExt = @"png";
// get the file manager
NSFileManager *fmanager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// get the doc directory
NSString *documentsDirectory = [paths objectAtIndex:0];
// get contents
NSArray *contents = [fmanager contentsOfDirectoryAtPath:documentsDirectory error:NULL];
// enum
NSEnumerator *e = [contents objectEnumerator];
NSString *fname;
// loop
while ((fname = [e nextObject])) {
// compare
    if ([[fname pathExtension] isEqualToString:fileExt]) {
     // remove it
        [fmanager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:fname] error:NULL];