0

How do I create a directory that will not be backed up automatically by iCloud. (I do not want to backup this directory or any files in this directory or subdirectories.)

I am creating a directory 'my_dir' as follows:

NSFileManager *fileManager = [NSFileManager defaultManager];

NSString *libraryPath = 
     [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
                                          NSUserDomainMask, YES) firstObject];

myDirPath = [libraryPath stringByAppendingPathComponent:@"my_dir"];

[fileManager createDirectoryAtPath:myDirPath 
             withIntermediateDirectories:NO 
             attributes:nil error:nil];

Is there a simple attribute that I can set? What can I do here to easily mark the directory 'my_dir' so that it is never backed up by iCloud?

I understand that this solution can be used to go back through existing files and directories:

NSURL *guidesURL = [NSURL fileURLWithPath:guidesPath]; [guidesURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:NULL]

The question is, is there a better way to do this by setting an attribute on the directory at directory creation time that applies to the directory and all subfiles?

To be clear is there an attribute that I can use with this call: [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject];

To exclude the directory from automatic backup?

APerson
  • 8,140
  • 8
  • 35
  • 49
Andrew Paul Simmons
  • 4,334
  • 3
  • 31
  • 39
  • possible duplicate of [Still backups to iCloud even when addSkipBackupAttributeToItemAtURL is implemented?](http://stackoverflow.com/questions/10786179/still-backups-to-icloud-even-when-addskipbackupattributetoitematurl-is-implement) – Paulw11 Nov 20 '14 at 21:26
  • Absolutely not a duplicate. Look at the answer to the other question Paulw11! The answer to the other question is as follows: NSURL *guidesURL = [NSURL fileURLWithPath:guidesPath]; [guidesURL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:NULL] Now take a moment to notice that in the case I listed above we are trying to add this flag while creating a directory without having to go back and run this final step. – Andrew Paul Simmons Nov 20 '14 at 23:08
  • Exactly. The answer to that question shows how to flag a directory to be excluded from iCloud – Paulw11 Nov 20 '14 at 23:08
  • To be clear is there an attribute that I can use with this call: [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject]; To exclude the directory from automatic backup? Or do I have to go back and apply the attribute to the NSURL file path after directory creation for each directory? – Andrew Paul Simmons Nov 20 '14 at 23:15
  • No, you have to do it in two steps - but if you flag the directory then it will exclude all files within that directory – Paulw11 Nov 20 '14 at 23:16
  • I see, so there is no better way... Well that is a direct answer. Thanks. – Andrew Paul Simmons Nov 20 '14 at 23:19

0 Answers0