915
技术社区[云栖]
NSFileManager扩展
// // NSFileManager+File.h // CloudShopping // // Created by ljy-335 on 14-8-4. // Copyright (c) 2014年 uni2uni. All rights reserved. // #import <Foundation/Foundation.h> /*! * @brief NSFileManager关于文件操作的扩展 * @author huangyibiao */ @interface NSFileManager (File) /*! * @brief 判断文件是否存在于沙盒中 * @param filePath 文件路径名 * @return 返回YES表示存在,返回NO表示不存在 */ - (BOOL)isFileExists:(NSString *)filePath; /*! * @brief 判断文件是否超时 * @param filePath 文件路径名 * @param timeout 限制的超时时间,单位为秒 * @return 返回YES表示超时,返回NO表示未超时 */ - (BOOL)isFile:(NSString *)filePath timeout:(NSTimeInterval)timeout; @end
//
// NSFileManager+File.m
// CloudShopping
//
// Created by ljy-335 on 14-8-4.
// Copyright (c) 2014年 uni2uni. All rights reserved.
//
#import "NSFileManager+File.h"
@implementation NSFileManager (File)
/*!
* @brief 判断文件是否存在于沙盒中
* @param fileName 文件路径名
* @return 返回YES表示存在,返回NO表示不存在
*/
- (BOOL)isFileExists:(NSString *)filePath {
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL result = [fileManager fileExistsAtPath:filePath];
return result;
}
/*!
* @brief 判断文件是否超时
* @param filePath 文件路径名
* @param timeout 限制的超时时间,单位为秒
* @return 返回YES表示超时,返回NO表示未超时
*/
- (BOOL)isFile:(NSString *)filePath timeout:(NSTimeInterval)timeout {
if ([[NSFileManager defaultManager] isFileExists:filePath]) {
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath
error:&error];
if (error) {
return YES;
}
if ([attributes isKindOfClass:[NSDictionary class]] && attributes) {
// NSLog(@"%@", attributes);
NSString *createDate = [attributes objectForKey:@"NSFileModificationDate"];
createDate = [NSString stringWithFormat:@"%@", createDate];
if (createDate.length >= 19) {
createDate = [createDate substringToIndex:19];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSDate *sinceDate = [formatter dateFromString:createDate];
NSTimeInterval interval = [[NSDate date] timeIntervalSinceDate:sinceDate];
return interval <= 0;
}
}
}
return YES;
}
@end
最后更新:2017-04-03 05:39:42
上一篇:
定制textField
下一篇:
给label添加超链接等处理
android屏幕自适应的四种方法
aFinal框架
The method setFilters(InputFilter[]) in the type Editable is not applicable
谢霆锋爱用的千元铁锅,在天猫国际俘获了一大波潮男
写给四年前刚开始编程的自己
[gcc核心扩展]关于gcc中的typeof以及其他东东
如何在 Linux 中安装最新的 Python 3.6 版本
《Linux From Scratch》第二部分:准备构建 第四章:最后的准备- 4.3. 添加 LFS 用户
史上五大最危险计算机黑客出炉 多数有犯罪前科
直播 | DPDK中国技术峰会2017