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

来源:互联网 发布:mac 网线转接头 编辑:程序博客网 时间:2024/05/18 14:22
    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);            }

 

原创粉丝点击