I found the code below to delete file in objective-c, but I want to only delete all files under directory of Caches
and keep the directory Caches
itsel
- (void) removeDocuments
{
NSString *docDir = // get documents directory
NSString *cacheDir = [docDir stringByAppendingPathComponent: @"cacheDir"];
// check if cache dir exists
// get all files in this directory
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *fileList = [fm contentsOfDirectoryAtPath: cacheDir error: nil];
// remove
for(NSInteger i = 0; i < [fileList count]; ++i)
{
NSString *fp = [fileList objectAtIndex: i];
NSString *remPath = [cacheDir stringByAppendingPathComponent: fp];
[fm removeItemAtPath: remPath error: nil];
}
}