文件系统扫描的工具类

文件系统扫描的工具类

说明

  • 递归扫描文件夹系统,并以树形结构组织起来
  • 支持沙盒、bundle扫描
  • 支持扫描深度设置
  • 用File对象表示一个扫描出来的文件,File对象包含了一个文件或者文件夹的基本文件信息(如文件名字,是否隐藏,文件扩展名,文件url地址等等),便于后续操作

源码

https://github.com/YouXianMing/iOS-Utilities

//
//  ViewController.m
//  FileManager
//
//  Created by YouXianMing on 15/11/19.
//  Copyright © 2015年 YouXianMing. All rights reserved.
//

#import "ViewController.h"
#import "FileManager.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    // Scan files.
    File *file = [FileManager scanRelatedFilePath:@"~/Library" maxTreeLevel:1];
    NSLog(@"

%@ 
%@

", file, file.subFiles);
    
    // Get the real file path from related file path.
    NSLog(@"%@", [FileManager theRealFilePath:@"~/Documents"]);
    NSLog(@"%@", [FileManager theRealFilePath:@"-"]);
    
    // Check the file at the given path exist or not.
    NSLog(@"%d", [FileManager fileExistWithRealFilePath:[FileManager theRealFilePath:@"~/Library/Caches"]]);
    NSLog(@"%d", [FileManager fileExistWithRealFilePath:[FileManager theRealFilePath:@"~/YouXianMing"]]);
}

@end

细节

原文地址:https://www.cnblogs.com/YouXianMing/p/5020946.html