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); }
本文深入探讨Swift语言中枚举的使用方法与高级特性,包括关联值、原始值、模式匹配等,通过实例讲解如何在实际开发中有效运用枚举。
70

被折叠的 条评论
为什么被折叠?



