Search code examples
iphoneobjective-ciosxcodensdocumentdirectory

How to delete files which contain words in the iOS documentsDirectory


I want to delete several image files in the documentsDirectory. There are already a large number of files in the documents directory, but I only want to delete the files which contain the word "Test" in their filename.

How can I go about doing this?


Solution

  • Pretty simple. Have a look at [NSFileManager contentsOfDirectoryAtPath:error:], which lists you all the files in the specified directory. Then you could filter/iterate the array according to your needs.

    To delete a file use [NSFileManager removeItemAtPath:error:].