• 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: Counting the number of files in a directory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Counting the number of files in a directory


  • Subject: Re: Counting the number of files in a directory
  • From: Ken Tozier <email@hidden>
  • Date: Tue, 6 Mar 2007 00:04:54 -0500

You could make a reusable category on NSFileManager like this

@interface NSFileManager (CatInfo)

+ (int) filesInDirectory:(NSString *) inPath;

@end

@implementation NSFileManager (CatInfo)

+ (int) filesInDirectory:(NSString *) inPath
{
FSRef ref;
Boolean isDir;
FSCatalogInfo catInfo;
const char *pathString = [inPath UTF8String];
OSStatus status = FSPathMakeRef(pathString, &ref, &isDir);

if (status == noErr)
{
if (isDir)
{
OSErr err = FSGetCatalogInfo(&ref, kFSCatInfoValence, &catInfo, NULL, NULL, NULL);
if (err == noErr)
return catInfo.valence;
else
NSLog(@"get cat info error: %hi", err);
}
else
NSLog(@"not a directory: %@", inPath);
}
else
NSLog(@"err status: %i", status);

return NSNotFound;
}


@end


And use it like this:

int		fileCount		= [NSFileManager filesInDirectory: @"some dir path"];

NSLog(@"file count: %i", fileCount);

Although it really doesn't have anything to do with an NSFileManager, creating it as category relates it conceptually

HTH

-Ken



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Counting the number of files in a directory
      • From: Christopher Hickman <email@hidden>
References: 
 >Counting the number of files in a directory (From: dew drops <email@hidden>)
 >Re: Counting the number of files in a directory (From: Michael Watson <email@hidden>)
 >Re: Counting the number of files in a directory (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: Dragging a folder in Interface Builder
  • Next by Date: Re: CoreData could not fulfill a fault
  • Previous by thread: Re: Counting the number of files in a directory
  • Next by thread: Re: Counting the number of files in a directory
  • Index(es):
    • Date
    • Thread