Strive printing out the baseURL
s of the URLs you’re getting:
print(fileURL.baseURL)
It’s best to see that these are all nil. Due to this, relativePath
returns simply returns the path
part:
This is identical as
path
ifbaseURL
is nil.
It seems that giving out absolute URLs is simply how enumerator(at:includingPropertiesForKeys:choices:errorHandler:)
behaves by default.
Thankfully, there may be an extra choice you could cross, in order that it producesRelativePathURLs
.
guard let fileEnumeratorIncludingSubFolder = FileManager.default.enumerator(
at: homeURL,
includingPropertiesForKeys: [],
choices: [.skipsHiddenFiles, .skipsPackageDescendants, .producesRelativePathURLs]) // right here!
else { fatalError() }