Re: NSFileManager miscount
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.