Nektarios
Nektarios

Reputation: 10351

OS X / Cocoa - how to read in every file from a directory?

What's the "right way" to read in every file from a directory on OS X using Cocoa? I need to get the filename of each file and then I need to pull it's contents in to one NSString.

Upvotes: 1

Views: 124

Answers (2)

John Bowers
John Bowers

Reputation: 1795

Get an enumerator for the path in question using the NSFileManager:

NSDirectoryEnumerator* enumerator = [[NSFileManager defaultManager] enumeratorAtPath:path];

Then call nextObject on the enumerator in a loop until it returns nil.

Upvotes: 0

Related Questions