Created
April 6, 2025 14:39
-
-
Save microtherion/1c2e687b30127fb5010ca15809c0757a to your computer and use it in GitHub Desktop.
Get a file URL from a FileWrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Horrifying idea, but it seems to work on Apple platforms | |
// This is NOT stable across mounting/unmounting a file system | |
extension FileWrapper { | |
var fileURL: URL? { | |
let attr = self.fileAttributes | |
guard let fileSystemNumber = attr["NSFileSystemNumber"] as? Int, | |
let fileSystemFileNumber = attr["NSFileSystemFileNumber"] as? Int | |
else { return nil } | |
return URL(string: "file:///.file/id=\(fileSystemNumber).\(fileSystemFileNumber)/") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work on macOS, as it turns out.