• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: File Extensions Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File Extensions Problem


  • Subject: Re: File Extensions Problem
  • From: Andrew Merenbach <email@hidden>
  • Date: Fri, 22 Aug 2008 00:22:42 -0700


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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: File Extensions Problem
      • From: Graham Cox <email@hidden>
References: 
 >File Extensions Problem (From: Adil Saleem <email@hidden>)
 >Re: File Extensions Problem (From: Michael Dautermann <email@hidden>)

  • Prev by Date: Re: File Extensions Problem
  • Next by Date: Re: File Extensions Problem
  • Previous by thread: Re: File Extensions Problem
  • Next by thread: Re: File Extensions Problem
  • Index(es):
    • Date
    • Thread