• 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: Small problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small problem


  • Subject: Re: Small problem
  • From: Nick Zitzmann <email@hidden>
  • Date: Sat, 14 Jun 2003 11:59:48 -0700

On Saturday, June 14, 2003, at 11:25 AM, Jesus De Meyer wrote:

In my Cocoa application I'm building a menu that has items from a
certain folder. Now, all works well but I get 2 items that shouldn't be
there: .DS_Store and Icon.
I have tried using the fileVisible method that I got on an earlier
mail, but that didn't work. Also checking wheater the item starts with
a "." or is equal to "icon" didn't work.

I have no idea how I cannot include these items. I use the
directoryContentsAtPath method from NSFileManager.

Try something like this: (disclaimer - written in Mail, untested, use at your own risk, etc.)

NSMutableArray *itemsInPath = [NSMutableArray arrayWithArray:[[NSFileManager defaultManager] directoryContentsAtPath:@"/somewhere"]]; // put your path in here
unsigned i, itemsInPathCount = [itemsInPath count];

for (i = 0 ; i < itemsInPathCount ; i++)
{
id objectAtIndex = [itemsInPath objectAtIndex:i];

if ([objectAtIndex isEqual:@".DS_Store"] || [objectAtIndex isEqual:@"Icon\r"]) // in Mac System 7, folder icon files always had a carriage return at the end of the file name, so if they still do (I don't know) then that ought to find them
{
[itemsInPath removeObjectAtIndex:i];
}
}

If the @"Icon\r" comparison check still doesn't work, then you could try calling "-rangeOfString:" to find out whether or not the string contains just the "Icon" bit... See the NSString docs for details.

Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page: http://dreamless.home.attbi.com/

"Great spirits have always encountered violent opposition from mediocre minds." - Albert Einstein
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >Small problem (From: Jesus De Meyer <email@hidden>)

  • Prev by Date: Small problem
  • Next by Date: Re: Cocoa's custom class delegate conventions
  • Previous by thread: Small problem
  • Next by thread: Re: Invisible files (was Re: Small problem)
  • Index(es):
    • Date
    • Thread