当前位置: 代码迷 >> 移动开发 >> NSFileManager 资料应用
  详细解决方案

NSFileManager 资料应用

热度:10669   发布时间:2013-02-26 00:00:00.0
NSFileManager 文件应用
- (void)clearDisk{    dispatch_async(self.ioQueue, ^    {        [[NSFileManager defaultManager] removeItemAtPath:self.diskCachePath error:nil];        [[NSFileManager defaultManager] createDirectoryAtPath:self.diskCachePath                                  withIntermediateDirectories:YES                                                   attributes:nil                                                        error:NULL];    });}- (void)cleanDisk{    dispatch_async(self.ioQueue, ^    {        NSDate *expirationDate = [NSDate dateWithTimeIntervalSinceNow:-self.maxCacheAge];        NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];        for (NSString *fileName in fileEnumerator)        {            NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];            NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];            if ([[[attrs fileModificationDate] laterDate:expirationDate] isEqualToDate:expirationDate])            {                [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];            }        }    });}-(int)getSize{    int size = 0;    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];    for (NSString *fileName in fileEnumerator)    {        NSString *filePath = [self.diskCachePath stringByAppendingPathComponent:fileName];        NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];        size += [attrs fileSize];    }    return size;}- (int)getDiskCount{    int count = 0;    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:self.diskCachePath];    for (NSString *fileName in fileEnumerator)    {        count += 1;    }        return count;}

?