# Cocoa and listing folder contents...



## konan (Jun 7, 2002)

How do I retreive the contents of a folder using Cocoa? In windows, there is the findfirst() and function retreive the first file in the folder, then the rest can be retreived via the findnext() function.

I was able to do this in OS X with the following bit

system("ls Folder/ > Listing.txt");
then I read the file Listing.txt to get the file names.

This is a little crude and I'd rather find a more elegant way to do it.

Again, any push in the right direction would be greatly appreciated
Konan


----------



## zots (Jun 7, 2002)

See NSFileManager .  Methods you would use are directoryContentsAtPath.  This will return an array of the files, so get the first file in the directory by calling [myArray objectAtIndex:0]


----------



## konan (Jun 11, 2002)

Thanks dude. That did the trick 

Konan


----------



## iconara (Jun 19, 2002)

check out NSDirectoryEnumerator in the documentation of Foundation and this article at CocoaDevCentral


theo


----------

