@implementation NSString (NSString_PathValid)
- (int)Interval
{
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self error:nil];
//NSLog(@"create date:%@",[attributes fileModificationDate]);
NSString *dateString = [NSString stringWithFormat:@"%@",[attributes fileModificationDate]];
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSDate *formatterDate = [inputFormatter dateFromString:dateString];
unsigned int unitFlags = NSDayCalendarUnit;
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *d = [cal components:unitFlags fromDate:formatterDate toDate:[NSDate date] options:0];
[inputFormatter release];
//NSLog(@"%d,%d,%d,%d",[d year],[d day],[d hour],[d minute]);
int result = [d day];
// return 0;
return result;
}
- (BOOL)isValid
{
if ([self Interval] < VALIDDAYS) { //VALIDDAYS = 有效時間天數
return YES;
}
return NO;
}
NSString *path =@"51ios/文件路徑";
if ([path isValid]){
// 有效
}
else{
// 無效
}