File Size Code
File Size Code
- Subject: File Size Code
- From: email@hidden
- Date: Sat, 8 May 2004 21:40:16 -0700
ok here's my code to add the file size of files/directories
- (void) queryFileSize;
{
NSFileManager *manager = [NSFileManager defaultManager];
NSDictionary *rule = [NSDictionary
dictionaryWithDictionary:[itemArray objectAtIndex:[backupTable
selectedRow]]];
NSArray *pathArray = [[rule objectForKey:@"path"]
componentsSeparatedByString:@":"];
NSEnumerator *e = [pathArray objectEnumerator];
id object;
int total = 0;
BOOL isDir;
while(object = [e nextObject])
{
if ([manager fileExistsAtPath:[object
stringByExpandingTildeInPath] isDirectory:&isDir] && isDir)
{
NSString *file;
NSDirectoryEnumerator *enumerator = [[NSFileManager
defaultManager] enumeratorAtPath:[object
stringByExpandingTildeInPath]];
//NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]
init];
while (file = [enumerator nextObject])
{
NSDictionary *fileSize = [manager
fileAttributesAtPath:file traverseLink:NO];
NSNumber *totalFileSize = [fileSize
objectForKey:NSFileSize];
total += [totalFileSize intValue];
}
//[pool release];
}
else
{
NSDictionary *fileSize = [manager
fileAttributesAtPath:[object stringByExpandingTildeInPath]
traverseLink:NO];
NSNumber *totalFileSize = [fileSize
objectForKey:NSFileSize];
total += [totalFileSize intValue];
}
}
NSLog(@"%d",total);
}
my problem is, its not reading the size for some reason it will on 1
file and then the rest come up as zero?
_______________________________________________
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.