获取文件属性
2016-12-16 16:59 supper_Ho 阅读(393) 评论(0) 编辑 收藏 举报//
// main.m
// 02-获取文件属性
//
// Created by apple on 14-3-21.
// Copyright (c) 2014年 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
/*
NSString * str = @"www.itcast.cn";
NSError * error;
BOOL isWriteSuccess = [str writeToFile:@"/Users/aplle/Desktop/test.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
if (isWriteSuccess)
{
NSLog(@"创建成功");
}
else
{
NSLog(@"error %@",error);
}
*/
//1.获取文件管理器
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * path = @"/Users/aplle/Desktop/test.txt";
NSError * error;
NSDictionary * dic = [fileManager attributesOfItemAtPath:path error:&error];
NSLog(@"dic %@",dic);
if (error == nil)
{
NSDate * date = [dic objectForKey:NSFileCreationDate];
NSString * size = [dic objectForKey:NSFileSize];
NSLog(@" date = %@, size = %@",date,size);
}
}
return 0;
}