您的位置:首页 > 移动开发 > Objective-C

objective-c NSArray 列出指定文件目录列表

2012-07-03 10:29 309 查看
NSString *path=@"/usr/local";

NSFileManager *myFileManager=[NSFileManager defaultManager];

NSDirectoryEnumerator *myDirectoryEnumerator;

NSArray *directoryContents;

myDirectoryEnumerator=[myFileManager enumeratorAtPath:path];

//列举目录内容

NSLog(@"用enumeratorAtPath:显示目录%@的内容:",path);

while((path=[myDirectoryEnumerator nextObject])!=nil)

{

NSLog(@"%@",path);

}


//用另外一种办法列举目录内容 .这个只列出当前目录下的列表。不会列出子目录下的文件

directoryContents=[myFileManager directoryContentsAtPath:@"/usr/local"];

NSLog(@"用directoryContentsAtPath:显示目录%@的内容:",@"/usr/local");

for(path in directoryContents)

{

NSLog(@"%@",path);

}





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: