哈哈,我是新手,下面为大家介绍一下在iOS开发中的如何实现file列表查看。
查看根目录下的文件列表
- NSArray *leveList=
- [[[NSFileManager alloc]init] contentsOfDirectoryAtPath: [NSHomeDirectory() stringByAppendingPathComponent:@""] error:nil];
- for (NSString *str in leveList) {
- NSLog(@"levelList:%@",str);
- }
- NSLog(@"count:%d",[leveList count] );
文件列表结果如下:
- 2013-06-14 16:18:14.513 helloword[853:c07] levelList:Documents
- 2013-06-14 16:18:14.533 helloword[853:c07] levelList:helloword.app
- 2013-06-14 16:18:14.534 helloword[853:c07] levelList:Library
- 2013-06-14 16:18:14.535 helloword[853:c07] levelList:tmp
- 2013-06-14 16:18:14.537 helloword[853:c07] count:4
查看Library文件列表
- NSArray *leveList=
- [[[NSFileManager alloc]init] contentsOfDirectoryAtPath: [NSHomeDirectory() stringByAppendingPathComponent:@"Library"] error:nil];
- for (NSString *str in leveList) {
- NSLog(@"Library:%@",str);
- }
- NSLog(@"count:%d",[leveList count] );
结果如下:
- 2013-06-14 16:26:49.475 helloword[1040:c07] Library:Caches
- 2013-06-14 16:26:49.478 helloword[1040:c07] Library:Preferences
- 2013-06-14 16:26:49.480 helloword[1040:c07] count:2