Posts tagged ‘NSFileManager’

Mac:得到一个目录内的内容

首先是打开一个目录

然后

1, 使用NSFileManager来得到这个目录的内容

NSArray *contentArray = [[NSFileManager defaultManager] 
	 contentsOfDirectoryAtURL:[[oPanel URLs] objectAtIndex:0] 
	//oPanel是上个帖子中的NSOpenPanel对象
	 includingPropertiesForKeys:[NSArray array]
	 options:0 
	 error:nil];
//我们得到一个Array的NSURL

2, 简单显示这个Array中的内容

	for(id innerUrl in contentArray)
	{
		NSLog([innerUrl absoluteString]);
	}

3, 结果

run
[Switching to process 3626]
Running…
2010-06-17 23:32:43.409 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0001.xml
2010-06-17 23:32:43.411 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0002.xml
2010-06-17 23:32:43.411 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0003.xml
2010-06-17 23:32:43.411 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0004.xml
2010-06-17 23:32:43.411 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0005.xml
2010-06-17 23:32:43.411 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0006.xml
2010-06-17 23:32:43.412 XML2HTML[3626:a0f] file://localhost/Users/kingmtn/Downloads/T01/T01n0007.xml


*在简单输出含有空格的URL的String的时候会出现一定乱码, 如果有需要, 我会去分析为什么