NSString *path = [NSString stringWithFormat:@"%@/Documents/",NSHomeDirectory()];
NSError *error = nil;
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
if (fileAttributes && !error) {
NSNumber *fileSize;
NSString *fileOwner;
NSDate *fileModDate, *creationDate;
//文件大小
if ((fileSize = [fileAttributes objectForKey:NSFileSize])) {
NSLog(@"文件大小 : %llu", [fileSize unsignedLongLongValue]);
}
//文件創(chuàng)建日期
if ((creationDate = [fileAttributes objectForKey:NSFileCreationDate])) {
NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *newString = [format stringFromDate:creationDate];
NSLog(@"文件創(chuàng)建時間 : %@", newString);
}
//文件所有者
if ((fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName])) {
NSLog(@"文件所有者 : %@", fileOwner);
}
//文件修改日期
if ((fileModDate = [fileAttributes objectForKey:NSFileModificationDate])) {
NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString *newString = [format stringFromDate:fileModDate];
NSLog(@"文件修改時間 : %@", newString);
}
}