0

How can I remove all of the photos that I've saved in NSHomeDirectory? They are photos, saved in a path formatted as follows" /var/mobile/Applications/3EEDBD68-5496-458D-9EF0-062746847C83/Photos/1234.png.

And what do I call if I only want to remove a certain photo (i.e. that 1234.png listed above)?

Baub
  • 5,004
  • 14
  • 56
  • 99
  • 1
    First have a look here: http://stackoverflow.com/questions/5499903/how-to-delete-all-the-files-under-my-apps-nsdocumentsdirectory/5499941#5499941 You can iterate through all the files, and when the name matches, delete it. – Rayfleck Nov 16 '11 at 21:09

2 Answers2

1

See NSFileManager.

bbum
  • 162,346
  • 23
  • 271
  • 359
1

To remove one item, you could call:

NSString *filePath = @"/var/mobile/Applications/3EEDBD68-5496-458D-9EF0-062746847C83/Photos/1234.png";
[[NSFileManager defaultManager] removeItemAtPath:filePath error:&error];

To remove all of them:

NSString *directoryPath = @"/var/mobile/Applications/3EEDBD68-5496-458D-9EF0-062746847C83/Photos/";
[[NSFileManager defaultManager] removeItemAtPath:directoryPath error:&error];
// Re-create the directory
[[NSFileManager defaultManager] createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:&error];
tobyc
  • 2,237
  • 2
  • 20
  • 26