//得到指定文件距离上次修改时间是否达到了指定值(秒)timeoutspa
+(BOOL)isTimeout:(NSString *)path time:(NSTimeInterval)timeout递归
{string
//得到当前时间io
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];object
NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];date
// 取得了文件上次修改的时间file
NSDate *d = [dict objectForKey:NSFileModificationDate];float
if (now-[d timeIntervalSince1970]>timeout) {im
return YES;error
}
return NO;
}
//计算文件夹下文件的总大小
+(float)fileSizeForDir:(NSString*)path
{
NSFileManager *fileManager = [NSFileManager defaultManager];
//记录总值
unsigned long long totalSize =0;
//得到指定路径path的全部内容(文件和文件夹)
NSArray* array = [fileManager contentsOfDirectoryAtPath:path error:nil];
for(int i = 0; i<[array count]; i++)
{
//拼接全路径
NSString *fullPath = [path stringByAppendingPathComponent:[array objectAtIndex:i]];
BOOL isDir;
//若是指定路径存在而且不是文件夹
//NSLog(@"fullPath:%@",fullPath);
//先判断是否存在,再判断是文件夹仍是文件
if ([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && !isDir)
{
//得到文件属性
NSDictionary *fileAttributeDic=[fileManager attributesOfItemAtPath:fullPath error:nil];
totalSize+=[[fileAttributeDic objectForKey:NSFileSize] unsignedLongLongValue];
}
else
{
//若是是文件夹,递归
totalSize+=[self fileSizeForDir:fullPath];
}
}
return totalSize;
}