目录操作,mac os 16-5

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        NSString    *fName = @"path.m";
        NSFileManager   *fm;
        NSString    *path, *tempdir, *extension, *homedir, *fullpath;
        NSArray     *components;
        
        fm = [NSFileManager defaultManager];
        
        //temp work dir
        tempdir = NSTemporaryDirectory();
        NSLog(@"\nTemporary Directory is %@", tempdir);
        
        //current dir get base dir
        path = [fm currentDirectoryPath];
        NSLog(@"\nBase dir is %@", [path lastPathComponent]);
        
        //create file fName in current dir ,all path
        fullpath = [path stringByAppendingPathComponent: fName];
        NSLog(@"\nfullpath to %@ is %@", fName, fullpath);
        
        //get file extension name
        extension = [fullpath pathExtension];
        NSLog(@"\nextension for %@ is %@", fullpath, extension);
        
        //get user main dir
        homedir = NSHomeDirectory();
        NSLog(@"\nYour home directory is %@", homedir);
        
        components = [homedir pathComponents];
        for( path in components)
            NSLog(@"%@", path);
    }
    return 0;
}

你可能感兴趣的:(目录操作,mac os 16-5)