IOS-Frameworks-Foundation-NSPathUtilities.h 文件夹路径

获取文件夹路径

1:IOS-Frameworks-Foundation-NSPathUtilities.h

NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory0 = documentsPath[0];

// /Users/ranzhou/Library/Developer/CoreSimulator/Devices/4414CD68-A19F-44FF-8746-B0BB937F2323/data/Containers/Data/Application/8E9C2C0A-8356-41DA-A47B-6B54CB7ACB9E/Documents

NSString * filename = [documentsDirectory stringByAppendingPathComponent:@"theFile.txt"];


2:IOS-Frameworks-Foundation-NSPathUtilities.h

NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, NO);

NSString *documentsDirectory1 = paths1[0];// ~/Documents


3:IOS-Frameworks-Foundation-NSPathUtilities.h

NSString *documentsDirectory2 = NSTemporaryDirectory();

// /Users/ranzhou/Library/Developer/CoreSimulator/Devices/4414CD68-A19F-44FF-8746-B0BB937F2323/data/Containers/Data/Application/2ED06C3A-36AF-403B-BD19-AEAA2C62F3B9/tmp/



//真机实测:

- (void)pathTest

{

    /*

     Returns the root directory of the user’s system.A string identifying the root directory of the user’s system.

     输出:/

     */

    NSString *documentsDirectory6 = NSOpenStepRootDirectory();

    NSLog(@"%@",documentsDirectory6);


    /*

     Returns the logon name of the current user.

     输出:mobile

     */

    NSString *documentsDirectory4 = NSUserName();

    NSLog(@"%@",documentsDirectory4);

    

    /*

     Returns a string containing the full name of the current user.

     输出:Mobile User

     */

    NSString *documentsDirectory5 = NSFullUserName();

    NSLog(@"%@",documentsDirectory5);

    

    /*

     The path to the home directory for the user specified by userName.

     输出:/var/mobile/Containers/Data/Application/C47EACC7-BA36-4A3A-A102-C9F8B52C131C

     */

    NSString *documentsDirectory7 = NSHomeDirectoryForUser(NSUserName());

    NSLog(@"%@",documentsDirectory7);

    

    /*

     Returns the path to either the user’s or application’s home directory, depending on the platform.

     输出:/var/mobile/Containers/Data/Application/C47EACC7-BA36-4A3A-A102-C9F8B52C131C

     */

    NSString *documentsDirectory3 =  NSHomeDirectory();

    NSLog(@"%@",documentsDirectory3);


    

    /*

     输出:~/Documents

     */

    NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, NO);

    NSString *documentsDirectory1 = paths1[0];

    NSLog(@"%@",documentsDirectory1);


    

    /*

     Creates a list of path strings for the specified directories in the specified domains. The list is in the order in which you should search the directories. If expandTilde is YES, tildes are expanded as described in stringByExpandingTildeInPath.

     You should consider using the NSFileManager methods URLsForDirectory:inDomains: and URLForDirectory:inDomain:appropriateForURL:create:error:. which return URLs, which are the preferred format.

     For more information on file system utilities, see File System Programming Guide.

     

     Note:

     The directory returned by this method may not exist. This method simply gives you the appropriate location for the requested directory. Depending on the application’s needs, it may be up to the developer to create the appropriate directory and any in between.

     

     输出:/var/mobile/Containers/Data/Application/C47EACC7-BA36-4A3A-A102-C9F8B52C131C/Documents

     */

    NSArray *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory0 = documentsPath[0];

    NSLog(@"%@",documentsDirectory0);


    

    /*

     A string containing the path of the temporary directory for the current user. If no such directory is currently available, returns nil.

     输出:/private/var/mobile/Containers/Data/Application/C47EACC7-BA36-4A3A-A102-C9F8B52C131C/tmp/

     */

    NSString *documentsDirectory2 = NSTemporaryDirectory();

    NSLog(@"%@",documentsDirectory2);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值