With this code I determine the file size if the checkbox is NSOnState, but with a folder value is always 0. The directory is correct.
Can you help me?
unsigned long long resultsize=0;
if(imagehistoryS.state == NSOnState) {
NSString *path = [NSString stringWithFormat:@"Users/Giovanni/Desktop/test", [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
NSNumber *fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] objectForKey:NSFileSize];
resultsize += [fileSize doubleValue];
}
[result setStringValue:[NSString stringWithFormat:@"Total size items selected: %f", resultsize]];
You’re passing in a string, and yet specifying the
NSUserDomainMask. I’ve tried this and it works.This is for an ARC environment.
Note, I’m using NSURLs instead of NSString filepaths as much as possible. Also, you don’t need to hardcode the user’s name in the search path.
Updated to show the specific folder as requested in the comments