Unexpected behaviour using URL.hasDirectory and URL.isFileURL

URL.hasDirectory and URL.isFileURL are reporting a directory url (such as this: file:///Users/user/Pictures/Test/Imports ) to be a "file".

I get this in my logs:

url: file:///Users/user/Pictures/Test/Imports
hasDirectoryPath: false
isFile: true

Is this caused by the schema being file:/// ?

The urls come straight from FileManager.DirectoryEnumerator so I have no control over how the URLs are instantiated.

What am I doing wrong? In the meantime, I'll be checking my URLs manually.

Workaround for anyone else passing through:

extension URL {
    var isDirectory: Bool {
        let resourceKeys = Set<URLResourceKey>([.isDirectoryKey])
        
        guard let resourceValues = try? self.resourceValues(forKeys: resourceKeys),
              let isDirectory = resourceValues.isDirectory
        else {
            return false
        }
        
        return isDirectory
    }
}

Unexpected behaviour using URL.hasDirectory and URL.isFileURL
 
 
Q