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);   
  • 相关阅读:
    C# 中的委托和事件
    sql笔记-group by 统计功能
    js,css小知识点记录
    sql小技巧
    《孙子兵法》总结
    .Net深复制、浅复制
    《君主论》
    php邮箱找回密码功能
    后台管理员账号不能同时登陆,以及登陆使对方强制下线功能
    好程序员应该读的30本书
  • 原文地址:https://www.cnblogs.com/appwgh/p/2517576.html
Copyright © 2011-2022 走看看