How can I check if a Swift URL represents a file or a directory?
There is a hasDirectoryPath attribute on the URL object, but there doesn't seem to be any 'intelligence' behind it.
It just reflects the isDirectory value passed to the URL.
code:
let URL1 = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
print(URL1.hasDirectoryPath)
let URL2 = URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true)
print(URL2.hasDirectoryPath)
output:
false
true