On Aug 22, 2008, at 12:10 AM, Michael Dautermann wrote:


On Aug 22, 2008, at 2:29 AM, Adil Saleem wrote:

Hi,

I want to display in a tableview, list of all media files (audio, video files) present in a certain directory.

Currently what i am doing is that i am getting the file names in an NSMutableArray using NSFileManager function directoryContentsAtPath

I get the list, but the problem is that it get all the files. I want only those files that have a certain extension (for example mp4, mp3). How can i do that.

Thanx in advance


After fetching the contents and before displaying contents in the table view, why not enumerate through the mutable array and remove any files that *do not have* the extensions you are looking for.

You can do something like:

NSString * fullFileName;

en = [ myMutableArray objectEnumerator ]

while(( fullFileName = [ en nextObject ) != NULL )
{
        // if the file is not an .mp3 file...
if( [[ fullFileName pathExtension ] compare: @".mp3" options: NSCaseInsensitiveSearch ] != NSOrderedSame )
                [ myMutableArray removeObject: fullFileName ]; // .. remove it

}

In other words, [ NSString pathExtension ] could be very helpful to you here.



Hi! It appears that you're removing an object from a mutable array while enumerating, so that will unfortunately not work. To modify your concept:

NSMutableArray *myMutableArray = [myOriginalArray copy];

for (NSString *fullFileName in myOriginalArray) {
if( [[ fullFileName pathExtension ] compare: @".mp3" options: NSCaseInsensitiveSearch ] != NSOrderedSame )
                [ myMutableArray removeObject: fullFileName ]; // .. remove it
}

// do something with myMutableArray...

Also of note is that the path extension probably shouldn't have the period in it.

Cheers,
        Andrew

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to