// basic path utilities
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *fName = @"path.m";
NSFileManager *fm;
NSString *path, *tempdir, *extention, *homedir, *fullpath;
NSArray *components;
NSString *upath = @"`stevekochan/progs/../ch16/./path.m";
// Need to create an instance of the file manager
fm = [NSFileManager defaultManager];
// get the temporary working directory
tempdir = NSTemporaryDirectory();
NSLog(@"Temproary directory is %@", tempdir);
// Extract the base directory form current directory
path = [ fm currentDirectoryPath];
NSLog(@"Base directory is %@", [path lastPathComponent]);
//create a full path to the file fName in curernt directory
fullpath = [ path stringByAppendingPathComponent: fName ];
NSLog(@"FullPath to %@ is %@ ", fName, fullpath);
// get the file name extention
extention = [ fullpath pathExtension];
NSLog(@"extention for %@ is %@", fullpath, extention);
// get users home directory
homedir = NSHomeDirectory ();
NSLog(@"Your Home directory is %@", homedir);
// Divide a path into its components
components = [homedir pathComponents];
for (path in components)
NSLog(@"%@", path);
// 'Standardize' a path
NSLog(@"%@ => %@", upath, [upath stringByStandardizingPath]);
[pool drain];
return 0;
}
[/pre]