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

Re: NSFileManager miscount


  • Subject: Re: NSFileManager miscount
  • From: Chris Ridd <email@hidden>
  • Date: Tue, 11 Mar 2003 18:58:03 +0000

On 11/3/03 6:12 pm, John Stokes <email@hidden> wrote:
> for(counter=0;counter<=totalGroups;counter++) {

Hm, that should be 'counter < totalGroups' otherwise you're looping 4 times
when totalGroups is 3.

> -Here's my problem: After creating the directory programmatically, if I have
> 3 files in the directory, "totalGroups" = 3. So far, so good.
>
> BUT, if I access the directory using the Finder, and then re-run my program,
> suddenly "totalGroups" = 4. This results in my program creating an extra,

Because the Finder has created a file called .DS_Store inside your
directory?

> Why? How do I get around this?

Instead of using directoryContentsAtPath and counting the results, use
enumeratorAtPath: and ignore .DS_Store if you see it. From the example in
NSFileManager's docs:

NSString *file;
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtPath:@"/MyAccount/Documents"];
while (file = [enumerator nextObject]) {
if (![file isEqualToString:@".DS_Store"]) {
// do something
}
}

Cheers,

Chris
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSFileManager miscount
      • From: John Stokes <email@hidden>
    • Re: NSFileManager miscount
      • From: John Stokes <email@hidden>
References: 
 >NSFileManager miscount (From: John Stokes <email@hidden>)

  • Prev by Date: Applescript question: Creating objects without location specifier
  • Next by Date: Re: vCal utility/framework?
  • Previous by thread: NSFileManager miscount
  • Next by thread: Re: NSFileManager miscount
  • Index(es):
    • Date
    • Thread