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: Mon, 10 May 2004 18:32:03 -0400
fileSize is nill and your NSLog statement is being called even if
[fileSize objectForKey:NSFileSize] returns false. Why NSLog is
displaying 0 is a mystery to me. (might be a "feature" of Objective-C
or NSLog.) This is one of the reasons I highly recommend always using {
} to inclose if statements, even if they are only one line.
Replace
NSDictionary *fileSize = [manager fileAttributesAtPath:file
traverseLink:YES];
with
NSDictionary * fileSize = [enumerator fileAttributes];
which returns a valid dictionary. It's probably more efficient anyway.
...
- Scott
On May 10, 2004, at 4:23 PM, email@hidden wrote:
ok so this is the directory enumerator code i'm using
NSString *file;
NSDirectoryEnumerator *enumerator = [[NSFileManager
defaultManager] enumeratorAtPath:[object
stringByExpandingTildeInPath]];
while (file = [enumerator nextObject])
{
if (![[[file lastPathComponent] substringToIndex:1]
isEqualToString:@"."])
{
NSNumber *totalFileSize;
NSDictionary *fileSize = [manager
fileAttributesAtPath:file traverseLink:YES];
if (totalFileSize = [fileSize
objectForKey:NSFileSize])
total += [totalFileSize intValue];
NSLog(@"%@ - Total: %d",file,[totalFileSize
intValue]);
}
}
and this is what it returns??
2004-05-10 13:19:40.881 RU[560] ABPerson.index - Total: 0
2004-05-10 13:19:40.882 RU[560] ABPerson.skIndex - Total: 0
2004-05-10 13:19:40.882 RU[560] AddressBook.data - Total: 0
2004-05-10 13:19:40.882 RU[560] AddressBook.data.beforesave - Total: 0
2004-05-10 13:19:40.883 RU[560] AddressBook.data.previous - Total: 0
2004-05-10 13:19:40.884 RU[560] Images - Total: 0
2004-05-10 13:19:40.884 RU[560]
Images/04E2B77A-6111-11D8-B407-000A9577D556 - Total: 0
2004-05-10 13:19:40.885 RU[560]
Images/04EE7574-6111-11D8-B407-000A9577D556 - Total: 0
2004-05-10 13:19:40.885 RU[560]
Images/3A84D5B2-694F-11D8-8A10-000A9577D556 - Total: 0
2004-05-10 13:19:40.885 RU[560]
Images/3AC2EAD4-694F-11D8-8A10-000A9577D556 - Total: 0
2004-05-10 13:19:40.886 RU[560] Images/CachedMacDotComPhotos - Total: 0
all sizes are 0 which cant be right the total is 1.9 MB? what a i
doing wrong?
_______________________________________________
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.