根据doc , NSDirectoryEnumerator
返回的路径应该相对于枚举的文件夹:
An NSDirectoryEnumerator object enumerates the contents of a directory, returning the pathnames of all files and directories contained within that directory. These pathnames are relative to the directory.
但是,当我这么做的时候
NSDirectoryEnumerator *dirEnum = [myFileManager enumeratorAtURL:URLFolder
includingPropertiesForKeys:nil
options:NSDirectoryEnumerationSkipsHiddenFiles
errorHandler:^BOOL(NSURL *url, NSError *error) {
return YES ;}];
我得到的是绝对路径!
这是正常现象还是已知问题?
最佳答案
函数enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:实际上应该返回绝对路径(请参阅链接中的讨论)。如果需要相对路径值,可以使用 enumeratorAtPath: .
关于cocoa-touch - NSDirectoryEnumerator : are the returned path relative?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20095666/