1

Here is my method to remove a file from the temporary directory:

- (void)removeFileNamed:(NSString *)fileName
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
    [fileManager removeItemAtPath:filePath error:nil];
}

How can I change this code to remove EVERY file from the temporary directory (i.e. no parameter required)?

EDIT

The solution from the duplicate question solved the issue for me.

user3784214
  • 105
  • 9

1 Answers1

1

E.g. by using a directory enumerator:

NSFileManager *fm = [NSFileManager defaultManager];
NSDirectoryEnumerator* en = [fm enumeratorAtPath:path];    
NSError* err = nil;
BOOL res;

NSString* file;
while (file = [en nextObject]) {
    res = [fm removeItemAtPath:[path stringByAppendingPathComponent:file] error:&err];
    if (!res && err) {
        NSLog(@"oops: %@", err);
    }
}
Mo Farhand
  • 1,144
  • 8
  • 21