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

谷博艺
2023-12-01

获取文件夹路径

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);

}


 类似资料: