IOS sandbox usage and iOS sandbox usage

Source: Internet
Author: User

IOS sandbox usage and iOS sandbox usage

Path for creating a sandbox:

NSFileManager * fileManager = [NSFileManager defaultManager];
NSArray * documentPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
NSLog (@ "documentPath % @", documentPaths );
NSString * ourDocumentPath = [documentPaths objectAtIndex: 0];
NSLog (@ "ourDocumentPath = % @", ourDocumentPath );
NSString * fileName = [ourDocumentPath stringByAppendingPathComponent: @ "MOVeee"];
[FileManager createDirectoryAtPath: fileName withIntermediateDirectories: YES attributes: nil error: nil];


Add folders and files


NSString * testPath = [testDirectory stringByAppendingPathComponent: @ "test00.txt"];
NSString * testPath2 = [testDirectory stringByAppendingPathComponent: @ "test22.txt"];
NSString * testPath3 = [testDirectory stringByAppendingPathComponent: @ "test33.txt"];
NSString * string = @ "write content, write String ";
[FileManager createFileAtPath: testPath contents: [string dataUsingEncoding: NSUTF8StringEncoding] attributes: nil];
[FileManager createFileAtPath: testPath2 contents: [string dataUsingEncoding: NSUTF8StringEncoding] attributes: nil];
[FileManager createFileAtPath: testPath3 contents: [string dataUsingEncoding: NSUTF8StringEncoding] attributes: nil];

Retrieve all file names in the directory Column

NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
NSString * documentsDirectory = [paths objectAtIndex: 0];
NSLog (@ "documentsDirectory % @", documentsDirectory );
NSFileManager * fileManage = [NSFileManager defaultManager];
NSString * myDirectory = [documentsDirectory stringByAppendingPathComponent: @ "test"];
NSArray * file = [fileManage subpathsOfDirectoryAtPath: myDirectory error: nil];
NSLog (@ "% @", file );
NSArray * files = [fileManage subpathsAtPath: myDirectory];
NSLog (@ "% @", files );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.