Sunday, April 21, 2013

NSFileManager changeCurrentDirectoryPath example objc


changeCurrentDirectoryPath:

Changes the path of the current working directory to the specified path.
- (BOOL)changeCurrentDirectoryPath:(NSString *)path
Parameters
path
The path of the directory to which to change.
Return Value
YES if successful, otherwise NO.
Discussion of [NSFileManager changeCurrentDirectoryPath]
All relative pathnames refer implicitly to the current working directory. Changing the current working directory affects only paths created in the current process.
Example of [NSFileManager changeCurrentDirectoryPath]

#import <Foundation/Foundation.h>

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

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSFileManager *filemgr = [NSFileManager defaultManager];

    if([filemgr changeCurrentDirectoryPath:@"/Users/me/"] == NO) {
        NSLog(@"Cannot change current directory");
    }

    [pool drain];
    return 0;
}