此代碼正確,但文件夾大小錯誤。如果我更改目錄,大小總是錯誤的。例如,「%@/Caches/com.apple.Safari/Webpage Previews」的大小爲23 MB,但我有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];
也是我用這個,但大小始終是錯誤的:
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];
你能幫助我嗎? 謝謝。
我喜歡任何以此開頭的帖子:此代碼是正確的,但其他一切都是錯誤的。 – 2012-01-30 17:27:33