• 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: Number of Files on Volume
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number of Files on Volume


  • Subject: Re: Number of Files on Volume
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Wed, 26 Nov 2008 15:51:43 +0100

Just a question, what was wrong with the CoreServices way ? (ie using FSGetVolumeInfo).

Le 26 nov. 08 à 15:19, Joe Turner a écrit :

Okay, maybe I spoke too soon... It worked twice. To get the number of files, I am doing this now:

- (NSNumber *)fileCount
{
NSDictionary *attributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:path];
return [NSNumber numberWithDouble:
([[attributes objectForKey:NSFileSystemNodes]
doubleValue] - [[attributes objectForKey:NSFileSystemFreeNodes]
doubleValue])];
}



The first two times I got the right number (752339), but now I am getting 18749375. Is this way even supposed to work?


Thanks!
On Nov 26, 2008, at 5:53 AM, Graham Lee wrote:

On 26/11/2008 08:28, "Andrew Farmer" <email@hidden> wrote:

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:

self.count = [NSNumber numberWithUnsignedLongLong:fsbuf.f_files];

In fact, f_files (when it works) reports the total number of nodes on the
filesystem, so you need to subtract f_ffree to find the number of nodes
which are occupied. Also, you need to test that neither of these numbers is
-1, as some filesystems don't support telling you that stuff.


Cheers,
Graham.
--
Graham Lee
Senior Macintosh Software Engineer, Sophos Plc.
+44 1235 540266
http://www.sophos.com/


_______________________________________________

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


_______________________________________________

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


  • Follow-Ups:
    • Re: Number of Files on Volume
      • From: Joe Turner <email@hidden>
References: 
 >Re: Number of Files on Volume (From: Graham Lee <email@hidden>)
 >Re: Number of Files on Volume (From: Joe Turner <email@hidden>)

  • Prev by Date: NSTrackingArea strange requirement
  • Next by Date: Re: Number of Files on Volume
  • Previous by thread: Re: Number of Files on Volume
  • Next by thread: Re: Number of Files on Volume
  • Index(es):
    • Date
    • Thread