Re: Number of Files on Volume
Re: Number of Files on Volume
- Subject: Re: Number of Files on Volume
- From: Andrew Farmer <email@hidden>
- Date: Wed, 26 Nov 2008 00:28:25 -0800
On 25 Nov 08, at 16:44, Joe Turner wrote:
I have ben trying to find a good way to get an accurate count of
files on a Volume. Using a NSDirectoryEnumerator takes way too long
(a couples minutes), so, I figured out how to do it on the old
Carbon FileManager using [FSGetVolumeInfo...]
Is there a better way of doing it? Maybe with Cocoa tools?
If you want a non-Carbon way of doing this, take a look at statfs64().
It's not technically Cocoa, but it's not Carbon and it works just fine.
An equivalent to your code would simply be:
#include <sys/param.h>
#include <sys/mount.h>
// ...
struct statfs64 fsbuf;
if(!statfs([volumePath fileSystemRepresentation], &fsbuf)) {
self.count = [NSNumber numberWithUnsignedLongLong:fsbuf.f_files];
} else {
// handle an error...
}
PS: Any reason why you're using a NSNumber as the property? It'll be a
lot easier to just use an integral type unless there's some pressing
need for an object.
_______________________________________________
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