NSFileManager:隐藏文件夹?

Ali*_*Ali 2 iphone xcode objective-c

我用下面的文件目录创建文件夹,我的问题是,如何隐藏这个文件夹,这样当我允许itune共享这个文件夹时不会出现给用户

/*创建新目录*/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];
Run Code Online (Sandbox Code Playgroud)

Mic*_*all 6

您可以通过在文件夹名称前加上一个点(.)来隐藏iTunes文件共享中的文件夹.因此Documents/MyHiddenFolder将会调用该路径Documents/.MyHiddenFolder

但是,现在建议将私有数据文件存储在Library目录中,或存储在其子目录中.有关更多信息,请参阅以下Apple问答.