Skip to content

Instantly share code, notes, and snippets.

@cmittendorf
Created August 1, 2015 10:51
Show Gist options
  • Save cmittendorf/fac92272a941a9cc64d5 to your computer and use it in GitHub Desktop.
Save cmittendorf/fac92272a941a9cc64d5 to your computer and use it in GitHub Desktop.
Returns the NSURLDocumentIdentifierKey for a file.
#!/usr/bin/env swift
import Foundation
let args = Process.arguments
if (args.count != 2) {
print("usage: \(args[0]) <file>\n")
exit(-1)
}
if let url = NSURL(fileURLWithPath:args[1]) where url.checkResourceIsReachableAndReturnError(nil) {
var error: NSError?
var rsrc: AnyObject?
var success = url.getResourceValue(&rsrc, forKey:NSURLDocumentIdentifierKey, error:&error)
if let number = rsrc as? NSNumber {
print("\(url.lastPathComponent!) : \(number)\n")
} else {
if let error = error {
print("Error: \(error)")
} else {
print("\(url.lastPathComponent!) : \(rsrc)\n")
}
}
exit(0)
} else {
print("File not found!\n")
exit(-1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment