Mac程序开发基础:得到一个目录内的内容

Mac程序开发基础:得到一个目录内的内容(转)
前面写了 Mac开发基础:打开一个目录的方法,下面继续,看看如何通过程序得到一个目录的内容。 1, 使用NSFileManager来得到这个目录的内容 NSArray * contentArray = [ [ NSFileManager defaultManage

前面写了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

你可能感兴趣的:(Mac程序开发基础:得到一个目录内的内容)