标签:
// // main.m // OC5_NSFileManger // // Created by zhangxueming on 15/6/19. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> //NSFileManager 是一个单例类 int main(int argc, const char * argv[]) { @autoreleasepool { //创建文件管理器对象 NSFileManager *fm1 = [NSFileManager defaultManager]; NSFileManager *fm2 = [NSFileManager defaultManager]; NSFileManager *fm3 = [NSFileManager defaultManager]; NSLog(@"fm1 = %p fm2 = %p fm3 = %p", fm1, fm2, fm3); //浅层遍历目录 //- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error //path: 目录的路径 //error: 打开目录出错, 会创建一个NSError对象 NSError *dicError=nil; NSArray *dicArray = [fm2 contentsOfDirectoryAtPath:@"/Users/zhangxueming/Desktop/Test" error:&dicError]; if (dicArray) { NSLog(@"dicArray = %@", dicArray); } else{ NSLog(@"error = %@", dicError); } //获取文件的扩展名 for (NSString *obj in dicArray) { NSLog(@"name = %@", [obj pathExtension]); } //深层遍历目录 //- (NSArray *)subpathsOfDirectoryAtPath:(NSString *)path error:(NSError **)error dicError = nil; NSArray *dicArray2 = [fm3 subpathsOfDirectoryAtPath:@"/Users/zhangxueming/Desktop/Test" error:&dicError]; if (dicArray2) { NSLog(@"dicArray2 = %@", dicArray2); } else { NSLog(@"%@", dicError); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/0515offer/p/4589573.html