Posted By

rabc on 07/14/10


Tagged

iphone


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

shimdh
umang_nine
bobbym245
rvachere
sb
Tintenklecks
cnathan


Delete files from Documents folder


 / Published in: Objective C
 

Delete the files in Documents folder if it's not a sqlite file.

  1. - (void)deleteFilesFromDocuments {
  2. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  3. NSFileManager* fm = [[[NSFileManager alloc] init] autorelease];
  4. NSDirectoryEnumerator* en = [fm enumeratorAtPath:path];
  5. NSError* err = nil;
  6. BOOL res;
  7. NSString* file;
  8. while (file = [en nextObject]) {
  9.  
  10. if ([file rangeOfString:@".sqlite"].location == NSNotFound) {
  11. res = [fm removeItemAtPath:[path stringByAppendingPathComponent:file] error:&err];
  12. if (!res && err) {
  13. NSLog(@"oops: %@", err);
  14. }
  15. }
  16. }
  17. }

Report this snippet  

You need to login to post a comment.