Skip to content

Instantly share code, notes, and snippets.

@taylanpince
Created May 16, 2012 22:34
Show Gist options
  • Save taylanpince/2714573 to your computer and use it in GitHub Desktop.
Save taylanpince/2714573 to your computer and use it in GitHub Desktop.
Mark Files in Directory with Do Not Backup Attribute
#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