zoukankan      html  css  js  c++  java
  • 浏览Document文件夹下面的所有文件夹和文件列表

        NSFileManager *fileManager = [NSFileManager defaultManager];    
         //在这里获取应用程序Documents文件夹里的文件及文件夹列表    
          
        NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, Y    ES) objectAtIndex:0];   
         
        NSError *error = nil;    
        NSArray *fileList = [[NSArray alloc] init];  
          
         //fileList便是包含有该文件夹下所有文件的文件名及文件夹名的数组    
        fileList = [fileManager contentsOfDirectoryAtPath:documentDir error:&error];    
          
          //以下这段代码则可以列出给定一个文件夹里的所有子文件夹名    
             
         NSMutableArray *dirArray = [[NSMutableArray alloc] init];  
         NSMutableArray *fileArray = [[NSMutableArray alloc] init];  
         BOOL isDir = NO;    
         //在上面那段程序中获得的fileList中列出文件夹名    
         for (NSString *file in fileList) {    
               NSString *path = [documentDir stringByAppendingPathComponent:file];    
              [fileManager fileExistsAtPath:path isDirectory:(&isDir)];    
             if (isDir) {    
                  [dirArray addObject:file];    
             }else{  
                   [fileArray addObject:file];  
               }  
             isDir = NO;    
           }    
         NSLog(@"文件夹下面的所有内容:%@",fileList);    
         NSLog(@"所有文件夹:%@",dirArray);   
         NSLog(@"所有文件:%@",fileArray);   
  • 相关阅读:
    CentOS 7 安装java 环境
    CentOS 7 替换网易yum 源
    九度:题目1553:时钟
    Maximum Subarray
    职场细节
    poj2524 Ubiquitous Religions
    九度 1526:朋友圈
    程序载入
    设备管理
    操作系统系列
  • 原文地址:https://www.cnblogs.com/appwgh/p/2517576.html
Copyright © 2011-2022 走看看