This code is correct but the folder size is wrong. If I change the directory the size is always wrong. For example the size of “%@/Caches/com.apple.Safari/Webpage Previews” is 23 MB, but I have 16.5 KB.
NSString *path = [NSString stringWithFormat:@"%@/Caches/com.apple.Safari/Webpage Previews", [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
NSNumber *fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil] objectForKey:NSFileSize];
resultsize += [fileSize unsignedLongLongValue];
also I used this but the size is always wrong:
NSFileManager *fm = [[NSFileManager alloc] init];
NSURL *LibraryURL = [[fm URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *previewsURL = [LibraryURL URLByAppendingPathComponent:@"Caches/com.apple.Safari/Webpage Previews"];
resultSize += [[[fm attributesOfItemAtPath:[previewsURL path] error:nil] objectForKey:NSFileSize] unsignedIntegerValue];
Can you help me?
Thanks.
If you want to get the size of all the files in a folder, you’ll need to iterate through the contents of the folder and get the sizes of the actual files:
(I haven’t tested this.)