• NSFileManager 遍历目录


     

        NSFileManager *fileManager = [NSFileManager defaultManager];

        NSString *documentPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

        // 遍历目录

        // 1.获取指定目录下的文件和目录,不遍历其下的子目录

        NSArray *fileArray1 = [[NSArray alloc]init];

        fileArray1 = [fileManager contentsOfDirectoryAtPath:documentPath error:nil];

        NSLog(@"fileArray1 = %@", fileArray1);

        // 2. 枚举器 遍历指定目录下的文件和子目录,遍历其下的子目录

        NSDirectoryEnumerator *directoryEnum = [fileManager enumeratorAtPath:documentPath];

        NSString *filePath;

        while (filePath = [directoryEnum nextObject]) {

            NSLog(@"filePath = %@", filePath);

        }

        // 3.遍历指定目录下的文件和子目录,遍历其下的子目录

        NSArray *fileArray3 = [fileManager subpathsAtPath:documentPath];

        NSLog(@"fileArray3 = %@", fileArray3);    

        // 4.3

        NSArray *fileArray4 = [fileManager subpathsOfDirectoryAtPath:documentPath error:nil];

        NSLog(@"fileArray4 = %@", fileArray4);

  • 相关阅读:
    SSM环境搭建
    spring 开发 Tars
    Tars --- Hello World
    Java IO流
    Java集合
    常用类
    Pwn With longjmp
    格式化字符串漏洞利用实战之 njctf-decoder
    一步一步 Pwn RouterOS之ctf题练手
    srop实战
  • 原文地址:https://www.cnblogs.com/xiangjune/p/5653782.html
Copyright © 2020-2023  润新知