【发布时间】:2011-11-20 15:07:32
【问题描述】:
我让用户从 NSOpenPanel 中选择一个文件夹。这将返回一个文件路径,例如:file://localhost/Folder。这是我的代码,一切都出错了:
NSURL *filePath = [openDlg URL]; //OpenDlg is my NSOpenPanel
NSString *s = [filePath absoluteString];
NSLog(@"%@",s);
NSError *error;
NSArray *b = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:s error:&error];
if (error) {
NSLog(@"%@",error);
}
NSLog(@"%lu",b.count);
这里,无论我选择哪个文件夹,都会发送此错误消息:文件夹“文件夹”不存在。” UserInfo=0x10518b320 {NSFilePath=file://localhost/Folder, NSUserStringVariant=( 文件夹 ), NSUnderlyingError=0x10515d5e0 "操作无法完成。(OSStatus 错误-43.)"}
这是怎么回事?!?如果这不是最好的方法,我该如何访问文件夹内的所有文件?
【问题讨论】:
标签: objective-c directory nsurl nsfilemanager nsopenpanel