FileManager.default.enumerator 输出的 Swift relativePath 属性是完整路径

问题描述 投票:0回答:0

我想获取相对路径,但我在下面的代码中获取了完整路径。 Xcode 14.3

let  homePath = NSHomeDirectory()
let  homeURL = URL(fileURLWithPath: ".", relativeTo: URL(fileURLWithPath: homePath))
guard let  fileEnumeratorIncludingSubFolder = FileManager.default.enumerator(
        at: homeURL,
        includingPropertiesForKeys: [],
        options: [.skipsHiddenFiles, .skipsPackageDescendants])
else { fatalError() }

for case let fileURL as URL in fileEnumeratorIncludingSubFolder {
    print(fileURL.relativePath)  // Expected relative path but full path
}
ios swift url relative-path nsfilemanager
© www.soinside.com 2019 - 2024. All rights reserved.