我在打印使用 NSFileManager 检索的文件名列表时遇到了一些问题。文档说它返回一个字符串数组 - 但我的输出是空白的。在下面的代码示例中,执行显示带有冒号的索引,仅此而已……我是一名长期的 java 程序员,但对 c/objc 来说完全是新手。我只是在滥用 printf 吗?谢谢你的帮助!
输出:
即将打印文件列表-----------
文件数:29
0:1:2:3:4:5:6:7 : 8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:
- (IBAction)printFileList:(id)sender{
NSFileManager *fm = [[NSFileManager alloc] init];
NSString *path = @"/";
NSArray *files = [fm contentsOfDirectoryAtPath:path error:NULL];
printf("About to print file list ----------------------- \n");
int fileCount = [files count];
printf("Number of files: %d", fileCount);
for(int i = 0; i<fileCount; i++){
printf("%d: %s\n", i, [files objectAtIndex:i]);
}
}