Creating a File Manager

- init

Returns an initialized NSFileManager instance.

Example

NSFileManager *fileManager = [[NSFileManager alloc]init];
NSLog(@"%@",fileManager);
		

Output

2014-04-12 08:25:46.240 iOS-Tutorial[2471:a0b] 
		

+ defaultManager

Returns the shared file manager object for the process.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"%@",fileManager);
		

Output

2014-04-12 08:26:45.672 iOS-Tutorial[2494:a0b] 
		

Locating System Directories

- URLForDirectory: inDomain: appropriateForURL: create: error:

Locates and optionally creates the specified common directory in a domain.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *resultURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSLog(@"%@",resultURL);
		

Output

2014-04-12 11:31:56.585 iOS-Tutorial[620:a0b] file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/
		

- URLsForDirectory:inDomains:

Returns an array of URLs for the specified common directory in the requested domains.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *resultURLs = [fileManager URLsForDirectory:NSDocumentationDirectory inDomains:NSUserDomainMask];
NSLog(@"%@",resultURLs);
		

Output

2014-04-12 11:34:13.793 iOS-Tutorial[637:a0b] (
    "file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Library/Documentation/"
)
		

Discovering Directory Contents

- contentsOfDirectoryAtURL: includingPropertiesForKeys: options: error:

Performs a shallow search of the specified directory and returns URLs for the contained items.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSArray *urls = [fileManager contentsOfDirectoryAtURL:directoryURL includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey, NSURLIsDirectoryKey, NSURLContentModificationDateKey, nil] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
NSLog(@"%@",urls);
		

Output

2014-04-12 11:48:23.415 iOS-Tutorial[710:a0b] (
    "file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/myDict.plist",
    "file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/sample-string.txt"
)		

- contentsOfDirectoryAtPath: error:

Performs a shallow search of the specified directory and returns the paths of any contained items.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSArray *urls = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"%@",urls); in progress
		

Output

2014-04-12 11:55:46.175 iOS-Tutorial[730:a0b] (
    ".DS_Store",
    "myDict.plist",
    "sample-string.txt"
)		

- enumeratorAtURL: includingPropertiesForKeys: options: errorHandler:

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified URL.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSEnumerator *enumerator = [fileManager enumeratorAtURL:directoryURL includingPropertiesForKeys:@[NSURLNameKey, NSURLIsDirectoryKey, NSURLContentModificationDateKey] options:NSDirectoryEnumerationSkipsHiddenFiles errorHandler:nil];
NSLog(@"%@",[enumerator allObjects]);
		

Output

2014-04-12 12:05:44.576 iOS-Tutorial[810:a0b] (
    "file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/myDict.plist",
    "file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/sample-string.txt"
)		

- enumeratorAtPath:

Returns a directory enumerator object that can be used to perform a deep enumeration of the directory at the specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSEnumerator *enumerator = [fileManager enumeratorAtPath:documentsDirectory];
NSLog(@"%@",[enumerator allObjects]);
		

Output

2014-04-12 11:59:42.406 iOS-Tutorial[753:a0b] (
    ".DS_Store",
    "myDict.plist",
    "sample-string.txt"
)
		

- subpathsOfDirectoryAtPath: error:

Performs a deep enumeration of the specified directory and returns the paths of all of the contained subdirectories.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSArray *resultArray = [fileManager subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"%@",resultArray);
		

Output

2014-04-12 12:13:35.038 iOS-Tutorial[824:a0b] (
    ".DS_Store",
    "myDict.plist",
    "sample-string.txt"
)		

- subpathsAtPath:

Returns an array of strings identifying the paths for all items in the specified directory.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSArray *resultArray = [fileManager subpathsAtPath:documentsDirectory];
NSLog(@"%@",resultArray);
		

Output

2014-04-12 12:15:36.908 iOS-Tutorial[842:a0b] (
    ".DS_Store",
    "myDict.plist",
    "sample-string.txt"
)
		

Creating and Deleting Items

- createDirectoryAtURL: withIntermediateDirectories: attributes: error:

Creates a directory with the given attributes at the specified URL.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *newDirectoryURL = [directoryURL URLByAppendingPathComponent:@"eezy"];
    NSError *error;
if ([fileManager createDirectoryAtURL:newDirectoryURL withIntermediateDirectories:YES attributes:nil error:&error]){
    NSLog(@"Create Sucess");
}
else{
    NSLog(@"Create error: %@", error);
}
		

Output

2014-04-12 12:33:46.959 iOS-Tutorial[907:a0b] Create Sucess
		

- createDirectoryAtPath: withIntermediateDirectories: attributes: error:

Creates a directory with given attributes at the specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *newDirectory = [documentsDirectory stringByAppendingPathComponent:@"eezy"];
    NSError *error;
if ([fileManager createDirectoryAtPath:newDirectory withIntermediateDirectories:NO attributes:nil error:&error]){
    NSLog(@"Create Sucess");
}
else{
    NSLog(@"Create error: %@", error);
}		

Output

2014-04-12 12:29:45.808 iOS-Tutorial[892:a0b] Create Sucess
		

- createFileAtPath: contents: attributes:

Creates a file with the specified content and attributes at the given location.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *newFilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
    NSError *error;
    if ([fileManager createFileAtPath:newFilePath contents:[@"Eezy Tuts" dataUsingEncoding:NSUTF8StringEncoding] attributes:nil]){
    NSLog(@"Create Sucess");
}
else{
    NSLog(@"Create error: %@", error);
}		

Output

2014-04-12 12:40:25.251 iOS-Tutorial[925:a0b] Create Sucess
		

- removeItemAtURL: error:

Removes the file or directory at the specified URL.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *fileURL = [directoryURL URLByAppendingPathComponent:@"eezy/test.txt"];
NSError *error;
if ([fileManager removeItemAtURL:fileURL error:&error]){
    NSLog(@"Remove Sucess");
}
else{
    NSLog(@"Remove error: %@", error);
}		

Output

2014-04-12 12:47:58.230 iOS-Tutorial[969:a0b] Remove Sucess
		

- removeItemAtPath: error:

Removes the file or directory at the specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
    NSError *error;
    if ([fileManager removeItemAtPath:filePath error:&error]){
    NSLog(@"Remove Sucess");
}
else{
    NSLog(@"Remove error: %@", error);
}		

Output

2014-04-12 12:43:42.905 iOS-Tutorial[939:a0b] Remove Sucess
		

Moving and Copying Items

- copyItemAtURL: toURL: error:

Copies the file at the specified URL to a new location synchronously.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *actualFileURL = [directoryURL URLByAppendingPathComponent:@"backupEezy/test.txt"];
NSURL *copyFileURL = [directoryURL URLByAppendingPathComponent:@"eezy/test.txt"];
NSError *error;
if ([fileManager copyItemAtURL:actualFileURL toURL:copyFileURL error:&error]){
    NSLog(@"Copy Success");
}
else{
    NSLog(@"Copy error: %@", error);
}
  		

Output

2014-04-12 12:59:29.384 iOS-Tutorial[1022:a0b] Copy Success
		

- copyItemAtPath: toPath: error:

Copies the item at the specified path to a new location synchronously.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualFilePath = [documentsDirectory stringByAppendingPathComponent:@"backupEezy/test.txt"];
NSString *copyFilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSError *error;
if ([fileManager copyItemAtPath:actualFilePath toPath:copyFilePath error:&error]){
    NSLog(@"Copy Success");
}
else{
    NSLog(@"Copy error: %@", error);
}		

Output

2014-04-12 13:02:47.669 iOS-Tutorial[1043:a0b] Copy Success
		

- moveItemAtURL: toURL: error:

Moves the file or directory at the specified URL to a new location synchronously.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
NSURL *actualFileURL = [directoryURL URLByAppendingPathComponent:@"eezy/test.txt"];
NSURL *moveFileURL = [directoryURL URLByAppendingPathComponent:@"backupEezy/test.txt"];
NSError *error;
if ([fileManager moveItemAtURL:actualFileURL toURL:moveFileURL error:&error]){
    NSLog(@"Move Success");
}
else{
    NSLog(@"Move error: %@", error);
}		

Output

2014-04-12 12:57:15.062 iOS-Tutorial[1010:a0b] Move Success
		

- moveItemAtPath: toPath: error:

Moves the file or directory at the specified path to a new location synchronously.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualFilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSString *moveFilePath = [documentsDirectory stringByAppendingPathComponent:@"backupEezy/test.txt"];
NSError *error;
if ([fileManager moveItemAtPath:actualFilePath toPath:moveFilePath error:&error]){
    NSLog(@"Move Success");
}
else{
    NSLog(@"Move error: %@", error);
}		

Output

2014-04-12 13:04:47.441 iOS-Tutorial[1056:a0b] Move Success
		

Determining Access to Files

- fileExistsAtPath:

Returns a Boolean value that indicates whether a file or directory exists at a specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"eezy.plist"];
NSLog(@"%d",[fileManager fileExistsAtPath:filePath]);		
	

Output

2014-04-12 09:21:07.861 iOS-Tutorial[2562:a0b] 0
		

- fileExistsAtPath: isDirectory:

Returns a Boolean value that indicates whether a file or directory exists at a specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
BOOL isDir = YES;
NSLog(@"%d",[fileManager fileExistsAtPath:documentsDirectory isDirectory:&isDir]);
		

Output

2014-04-12 09:24:54.254 iOS-Tutorial[2586:a0b] 1
		

- isReadableFileAtPath:

Returns a Boolean value that indicates whether the invoking object appears able to read a specified file.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%d",[fileManager isReadableFileAtPath:actualfilePath]);
		

Output

2014-04-12 13:08:25.127 iOS-Tutorial[1079:a0b] 1
		

- isWritableFileAtPath:

Returns a Boolean value that indicates whether the invoking object appears able to write to a specified file.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%d",[fileManager isWritableFileAtPath:actualfilePath]);
		

Output

2014-04-12 13:09:31.016 iOS-Tutorial[1100:a0b] 1
		

- isExecutableFileAtPath:

Returns a Boolean value that indicates whether the operating system appears able to execute a specified file.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%d",[fileManager isExecutableFileAtPath:actualfilePath]);
		

Output

2014-04-12 13:10:34.779 iOS-Tutorial[1117:a0b] 0
		

- isDeletableFileAtPath:

Returns a Boolean value that indicates whether the invoking object appears able to delete a specified file.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%d",[fileManager isDeletableFileAtPath:actualfilePath]);
		

Output

2014-04-12 13:11:09.752 iOS-Tutorial[1127:a0b] 1
		

Getting and Setting Attributes

- componentsToDisplayForPath:

Returns an array of strings representing the user-visible components of a given path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%@",[fileManager componentsToDisplayForPath:actualfilePath]);
		

Output

2014-04-12 13:11:43.236 iOS-Tutorial[1138:a0b] (
    "/",
    Users,
    rajkumar,
    Library,
    "Application Support",
    "iPhone Simulator",
    "7.0",
    Applications,
    "D6203A56-1113-4762-A533-D7AA6AB60356",
    Documents,
    eezy,
    "test.txt"
)
		

- displayNameAtPath:

Returns the display name of the file or directory at a specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%@",[fileManager displayNameAtPath:actualfilePath]);
		

Output

2014-04-12 13:12:24.569 iOS-Tutorial[1149:a0b] test.txt
		

- attributesOfItemAtPath:error:

Returns the attributes of the item at a given path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%@",[fileManager attributesOfItemAtPath:actualfilePath error:nil]);
		

Output

2014-04-12 13:13:29.018 iOS-Tutorial[1162:a0b] {
    NSFileCreationDate = "2014-04-12 07:22:51 +0000";
    NSFileExtensionHidden = 0;
    NSFileGroupOwnerAccountID = 20;
    NSFileGroupOwnerAccountName = staff;
    NSFileModificationDate = "2014-04-12 07:22:51 +0000";
    NSFileOwnerAccountID = 501;
    NSFilePosixPermissions = 420;
    NSFileReferenceCount = 1;
    NSFileSize = 8;
    NSFileSystemFileNumber = 4273863;
    NSFileSystemNumber = 16777217;
    NSFileType = NSFileTypeRegular;
}
		

- attributesOfFileSystemForPath: error:

Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%@",[fileManager attributesOfFileSystemForPath:actualfilePath error:nil]);
		

Output

2014-04-12 13:14:16.377 iOS-Tutorial[1174:a0b] {
    NSFileSystemFreeNodes = 7815572;
    NSFileSystemFreeSize = 32012582912;
    NSFileSystemNodes = 121886742;
    NSFileSystemNumber = 16777217;
    NSFileSystemSize = 499248103424;
}
		

- setAttributes: ofItemAtPath: error:

Sets the attributes of the specified file or directory.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%d",[fileManager setAttributes:@{NSFileModificationDate: [NSDate date]} ofItemAtPath:actualfilePath error:nil]);
		

Output

2014-04-12 13:18:47.572 iOS-Tutorial[1191:a0b] 1
		

Getting and Comparing File Contents

- contentsAtPath:

Returns the contents of the file at the specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%@",[[NSString alloc]initWithData:[fileManager contentsAtPath:actualfilePath] encoding:NSUTF8StringEncoding]);		

Output

2014-04-12 13:23:01.546 iOS-Tutorial[1224:a0b] Eezy Tut
		

- contentsEqualAtPath:andPath:

Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSString *secondFilePath = [documentsDirectory stringByAppendingPathComponent:@"backupEezy/test.txt"];
NSLog(@"%d",[fileManager contentsEqualAtPath:actualfilePath andPath:secondFilePath]);
		

Output

2014-04-12 13:24:32.946 iOS-Tutorial[1240:a0b] 1
		

Converting File Paths to Strings

- fileSystemRepresentationWithPath:

Returns a C-string representation of a given path that properly encodes Unicode strings for use by the file system.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *actualfilePath = [documentsDirectory stringByAppendingPathComponent:@"eezy/test.txt"];
NSLog(@"%s",[fileManager fileSystemRepresentationWithPath:actualfilePath ]);
		

Output

2014-04-12 13:25:25.527 iOS-Tutorial[1254:a0b] /Users/rajkumar/Library/Application Support/iPhone Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/eezy/test.txt
		

Managing the Current Directory

- changeCurrentDirectoryPath:

Changes the path of the current working directory to the specified path.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *directoryPath = [documentsDirectory stringByAppendingPathComponent:@"eezy"];
NSLog(@"%d",[fileManager changeCurrentDirectoryPath:directoryPath]);
		

Output

2014-04-12 13:27:55.054 iOS-Tutorial[1268:a0b] 1
		

- currentDirectoryPath

Returns the path of the program’s current directory.

Example

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *directoryPath = [documentsDirectory stringByAppendingPathComponent:@"eezy"];
NSLog(@"%d",[fileManager changeCurrentDirectoryPath:directoryPath]);
NSLog(@"%@",[fileManager currentDirectoryPath]);
		

Output

2014-04-12 13:28:52.747 iOS-Tutorial[1281:a0b] 1
2014-04-12 13:28:52.748 iOS-Tutorial[1281:a0b] /Users/rajkumar/Library/Application Support/iPhone Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/eezy
		

Advertisements