Created
May 16, 2012 22:34
-
-
Save taylanpince/2714573 to your computer and use it in GitHub Desktop.
Mark Files in Directory with Do Not Backup Attribute
This file contains 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
#include <sys/xattr.h> | |
- (NSInteger)markFilesInDirectoryAsDoNotBackup:(NSString *)path { | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
NSDirectoryEnumerator *directoryEnumerator = [fileManager enumeratorAtPath:path]; | |
NSString *filePath = nil; | |
NSInteger count = 0; | |
const char *attrName = "com.apple.MobileBackup"; | |
u_int8_t attrValue = 1; | |
while (filePath = [directoryEnumerator nextObject]) { | |
setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); | |
count += 1; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment