Created
November 17, 2014 10:59
-
-
Save norio-nomura/4fcafe793b4f120fbf48 to your computer and use it in GitHub Desktop.
NSURLIsExcludedFromBackupKeyがtrueなものをリストアップする
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 xcrun swift | |
import Cocoa | |
extension NSURL { | |
var isDirectory: Bool { | |
return resourceValue(NSURLIsDirectoryKey) | |
} | |
var isExcludedFromBackup: Bool { | |
return resourceValue(NSURLIsExcludedFromBackupKey) | |
} | |
func resourceValue(resourceKey: NSString) -> Bool { | |
var resourceValue: AnyObject? | |
var error: NSError? | |
var result = false | |
if getResourceValue(&resourceValue, forKey: resourceKey, error: &error) { | |
if let number = resourceValue as? NSNumber { | |
result = number.boolValue | |
} else { | |
println("error: \(self) for key: \(resourceKey)") | |
} | |
} else { | |
println("error: \(error?.localizedDescription) on \(self) for key: \(resourceKey)") | |
} | |
return result | |
} | |
} | |
func printExcludedFromBackupContentsAtURL(targetURL: NSURL) { | |
let keys = [NSURLIsDirectoryKey, NSURLIsExcludedFromBackupKey] as [AnyObject] | |
var error: NSError? | |
if let contents = NSFileManager.defaultManager().contentsOfDirectoryAtURL(targetURL, includingPropertiesForKeys: keys, options: nil, error: &error) as? [NSURL] { | |
for url in contents { | |
if url.isExcludedFromBackup { | |
println(url.path!) | |
} else if url.isDirectory { | |
printExcludedFromBackupContentsAtURL(url) | |
} | |
} | |
} else { | |
println("\(targetURL.path!): \(error!.localizedDescription)") | |
} | |
} | |
var path = Process.arguments.count > 1 ? Process.arguments[1] : NSFileManager.defaultManager().currentDirectoryPath | |
if let url = NSURL(fileURLWithPath: path) { | |
printExcludedFromBackupContentsAtURL(url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment