2

I use the below to create folder in document directory , my question is , how to make this folder hidden , such that when I allow itune share this folder not appear to the user

/* Create new directory */ NSFileManager *filemgr; NSArray *dirPaths; NSString *docsDir; NSString *newDir;

filemgr =[NSFileManager defaultManager];

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 
                                               NSUserDomainMask, YES);

docsDir = [dirPaths objectAtIndex:0];

newDir = [docsDir stringByAppendingPathComponent:@"Patients"];

NSLog(newDir);

if(! [self SearchForDirectory:newDir] )
{
    NSLog(@"directory Not Exists");

    if ([filemgr createDirectoryAtPath:newDir withIntermediateDirectories:YES attributes:nil error: NULL] == NO)
    {
        NSLog(@"Failed to create directory");
    }
}
else{
    NSLog(@"directory Exists");

}
[filemgr release];
Tony Adams
  • 691
  • 1
  • 9
  • 29
Ali
  • 1,975
  • 5
  • 36
  • 55

2 Answers2

6

You can make a folder hidden from iTunes file sharing by prepending the folder name with a dot (.). So the path would be Documents/MyHiddenFolder would be called Documents/.MyHiddenFolder

However, it is now recommended that private data files should be stored in the Library directory, or within a sub-directory of it. Please see the following Apple Q&A for more information.

Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
1

The Documents directory is for the user's documents. If you're trying to hide files from there, chances are they aren't documents and you should be storing the files in one of the other directories. What files are we talking about?

Note that including non-documents in that directory with iTunes file sharing enables is grounds for rejection from the App Store.

Jim
  • 72,985
  • 14
  • 101
  • 108
  • There are several cases for having hidden files/folders in the documents directory. The documents directory is the only documented place where you can store user data, such as databases, where it will be backed up and restored correctly. There is no other documented location within the app's sandbox where you can do this. – Michael Waterfall Mar 06 '11 at 14:24
  • The Library directory is backed up. If you don't want the user to see the files, but you do want them to be backed up, that is usually the best place for them. See my edit for a link to the documentation. – Jim Mar 06 '11 at 14:34
  • Hmm, interesting, the docs have changed since I last looked at them. Before it only stated that `Documents` and `Library/Preferences` were backed up. I wonder if this is different in older versions of iTunes/iOS. Risky to test! They still state that `Documents` is where you should store "user documents and application data files that need to be backed up". Perhaps it's a little ambiguous. – Michael Waterfall Mar 06 '11 at 14:56
  • The only mention of changes to that section in the document changelog is from 2008, before iOS 3.0 was released. You can't even target 2.x any more. It's not a problem. – Jim Mar 06 '11 at 15:14
  • No it's most certainly changed. See this [archived version](http://www.andreasacca.com/public/downloads/documenti/iPhoneAppProgrammingGuide.pdf) back in 2009. It only stated that `Library/Preferences` was backed up. This documentation section was the same in early 2010 when the iPad & 3.2 was in beta. There was lots of discussion on the dev forums relating to this. Since then I've just noticed [this Q&A](http://developer.apple.com/library/ios/#qa/qa2010/qa1699.html) was released in mid-2010 to clarify the issue, and the docs were most likely changed around then to reflect this. – Michael Waterfall Mar 06 '11 at 15:45
  • But yes, to conclude, it is now well documented that you can indeed use the `Library` directory to store data. Perhaps in a directory you create "Application Support" to reflect OS X. – Michael Waterfall Mar 06 '11 at 15:47
  • Thanks for the info. That Q&A is the definitive answer to this question, I suggest you post it as an answer instead of just a comment. – Jim Mar 06 '11 at 15:55
  • Okay I've amended my answer. Thanks for the clarification on this issue, I had no idea that the docs had changed. Looks like I've got an update to my app to make! – Michael Waterfall Mar 06 '11 at 16:49