3

how to check the extensions of files in directory or search for certain extension amog different extensions , any suggestion to do that for iphone applications

Best regards

Ali
  • 1,975
  • 5
  • 36
  • 55
  • 1
    this question is related http://stackoverflow.com/questions/499673/getting-a-list-of-files-in-a-directory-with-a-glob – Ben Clayton Mar 08 '11 at 18:31

1 Answers1

7

You can use NSFileManager's -contentsOfDirectoryAtPath:error: method to get an array with the contents of a directory (as strings). NSString has a -pathExtension method that makes it easy to get the file extension. All that remains is to iterate over the array looking for strings whose -pathExtension matches the extension you're looking for. Alternately, you could probably use -filteredArrayUsingPredicate: to identify the matching strings.

Vineet Singh
  • 4,009
  • 1
  • 28
  • 39
Caleb
  • 124,013
  • 19
  • 183
  • 272
  • are there any examples to clarify your wors – Ali Mar 08 '11 at 18:46
  • 2
    Read Ben Clayton's comment. Your question is pretty much a duplicate of the one linked, and there's some code there that does what I wrote. But out of curiousity and my own desire to write better answers, which part seems difficult? – Caleb Mar 08 '11 at 18:55