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

    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);
        
    }