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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:].