Re: glitch in my size code?
Re: glitch in my size code?
- Subject: Re: glitch in my size code?
- From: Scott Ahten <email@hidden>
- Date: Tue, 11 May 2004 03:17:21 -0400
I too thought the file size was an int from the docs.
After changing the datatype to unsigned long long, my test code looks
like...
NSString *file;
NSDictionary *fattrs;
NSNumber *fsize;
NSDate *moddate;
NSFileManager * fileManager = [NSFileManager defaultManager];
NSDirectoryEnumerator *enumerator = [fileManager
enumeratorAtPath:archivePath];
unsigned long long totalBytes = 0;
while (file = [enumerator nextObject]) {
NSLog(file);
fattrs = [enumerator fileAttributes];
//NSLog([fattrs description]);
if ([fattrs objectForKey:NSFileType] == NSFileTypeRegular) {
if (fsize = [fattrs objectForKey:NSFileSize]) {
totalBytes += [fsize unsignedLongLongValue];
NSLog(@"Size: %qu", [fsize unsignedLongLongValue]);
}
if (moddate = [fattrs objectForKey:NSFileModificationDate]) {
//NSLog(@"Modify Date: %@\n", [moddate description]);
}
}
}
NSLog(@"Total Bytes: %qu", totalBytes);
---
Sorry if this is an obvious question, but in why did this section in
chewtoy's code display 0 instead of crashing?
if (totalFileSize = [fileSize objectForKey:NSFileSize])
total += [totalFileSize intValue];
NSLog(@"%@ - Total: %d",file,[totalFileSize intValue]);
Since the dictionary is empty, the key NSFileSize is not found and
totalFileSize is nill. Yet NSLog displayed "total: 0" anyway?
- Scott
On May 11, 2004, at 1:27 AM, Scott Anguish wrote:
On May 10, 2004, at 5:46 PM, Glenn Andreas wrote:
if (totalFileSize = [fileSize
objectForKey:NSFileSize])
total += [totalFileSize intValue];
Is total (properly) declared as an "unsigned long long"? File size
is measured in unsigned long long, not int.
hrm.. The doc lists intValue for those, so that's likely where (s)he
is getting that from.
I've filed a bug.
_______________________________________________
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.
- - - - -
:: email@hidden
::
http://www.pixelfreak.net
- - - - -
_______________________________________________
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.