Skip to main content

Remove All Images from Document Directory




-(void)removeImagesFromDocumentDic{
    /* dir: the directory where your files are */
    NSFileManager *fm = [NSFileManager defaultManager];
    NSError *error = nil;
    NSString *docDirPath  =   [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSArray *items = [fm contentsOfDirectoryAtPath:docDirPath error:&error];
    if (error) { /* ... */ }
    
    /* delete png files */
    for (NSString *item in items) {
        if ([[item pathExtension] isEqualToString:@"png"]) {
            NSString *path = [docDirPath stringByAppendingPathComponent:item];
            [fm removeItemAtPath:path error:&error];
            if (error)
            { /* ... */ }
        }
    }
}

Comments