Search code examples
objective-ciosnsdocumentdirectory

Get the size of NSDocumentDirectory and clear its content


I am working on an iphone application.

The application downloads images from the server and save them on the phone using the following

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath2 = [NSString stringWithFormat:@"%@/%@.png", documentsDirectory, fileName];

[UIImagePNGRepresentation(imageToSave) writeToFile:filePath2 atomically:YES];

My questions is:

Is there a way I can get the size of the folder it is saving in? because I am saving images and i want to keep track of its size. And when it exceeds a certain size I want to clear it. And how can I clear the images that I saved? should I loop on them one by one and remove? or can I clear directly the entire cached images?

thank you


Solution

  • refer following question : Easy way to get size of folder (ObjC/Cocoa)?

    By this you can get the size of the folder. You can use NSFileManager to clear the contents of the path.