HomeiOS Developmentios - Swift relativePath property that FileManager.default.enumerator outputs is full path

ios – Swift relativePath property that FileManager.default.enumerator outputs is full path


Strive printing out the baseURLs 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 if baseURL 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() }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments