IOS NSFileManager 获取文件夹名称,文件名称等

NSFileManager *fileManager= [NSFileManager defaultManager];

//在这里获取应用程序Documents文件夹里的文件及文件夹列表

NSArray *documentPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentDir= [documentPaths objectAtIndex:0];

NSError *error=nil;

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

//fileList便是包含有该文件夹下所有文件的文件名及文件夹名的数组

fileList= [fileManager contentsOfDirectoryAtPath:documentDir error:&error];

以下这段代码则可以列出给定一个文件夹里的所有子文件夹名

NSMutableArray *dirArray= [[NSMutableArray alloc] init];

BOOLisDir=NO;

//在上面那段程序中获得的fileList中列出文件夹名

for (NSString *file in fileList) {

NSString *path= [documentDir stringByAppendingPathComponent:file];

[fileManager fileExistsAtPath:path isDirectory:(&isDir)];

if (isDir) {

[dirArray addObject:file];

}

isDir=NO;

}

NSLog(@"Every Thing in the dir:%@",fileList);

NSLog(@"All folders:%@",dirArray);


以上文章转自:http://blog.csdn.net/ios_che/article/details/7287266

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容