Created
August 1, 2015 10:51
-
-
Save cmittendorf/fac92272a941a9cc64d5 to your computer and use it in GitHub Desktop.
Returns the NSURLDocumentIdentifierKey for a file.
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
#!/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