// For the error message NSError * error; // create the File Manager NSFileManager * fileMgr = [NSFileManager defaultManager]; // point to the file directory NSString * documentsDirectory = [NSHomeDirectory () stringByAppendingPathComponent: @ "Documents"]; // create a directory [[NSFileManager defaultManager] createDirectoryAtPath: [NSString stringWithFormat: @ "% @/myFolder", NSHomeDirectory ()] withIntermediateDirectories: YES attributes: nil error: & error];/** <create a file *// /File we want to create in the documents directory the File we want to create will appear in the File directory // Result is:/Documents/file1.txt and the Result is: /Documents/file1.txt NSString * filePath = [documentsDirectory stringByAppendingPathComponent: @ "file1.txt"]; // the string to be written NSString * str = @ "iPhoneDeveloper Tips \ nhttp: // iPhoneDevelopTips, com "; // write the file [str writeToFile: filePath atomically: YES encoding: NSUTF8StringEncoding error: & error]; // display the file directory Rong NSLog (@ "Documentsdirectory: % @", [fileMgr contentsOfDirectoryAtPath: documentsDirectory error: & error]); /** <rename a file * // rename the file NSString * filePath2 = [documentsDirectory stringByAppendingPathComponent: @ "file2.txt"] by moving the file; // determine whether to move if ([fileMgr moveItemAtPath: filePath toPath: filePath2 error: & error]! = YES) NSLog (@ "Unable to move file: % @", [error localizedDescription]); // displays the NSLog (@ "Documentsdirectory: % @", [fileMgr contentsOfDirectoryAtPath: documentsDirectory error: & error]);/** <delete a file * // determine whether to delete the file in filePath2 if ([fileMgr removeItemAtPath: filePath2 error: & error]! = YES) NSLog (@ "Unable to delete file: % @", [error localizedDescription]); // displays the NSLog (@ "Documentsdirectory: % @", [fileMgr contentsOfDirectoryAtPath: documentsDirectory error: & error]);/** <obtains the list of files and folders in a directory */NSFileManager * fileManager = [NSFileManager defamanager]; // obtain the list of files and folders in the application Documents folder NSArray * documentPaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * documentDir = [documentPaths objectAtIndex: 0]; NSError * error2 = nil; NSArray * fileList = [[NSArray alloc] init]; // fileList is the array fileList = [fileManager contentsOfDirectoryAtPath: documentDir error: & error2] that contains the file names and folder names of all files in the folder. /** <list all subfolders in a given folder */NSMutableArray * dirArray = [[NSMutableArray alloc] init]; BOOL isDir = NO; // list the folder name for (NSString * file in fileList) {NSString * path = [documentDir stringByAppendingPathComponent: file]; [fileManager fileExistsAtPath: path isDirectory :( & isDir)]; if (isDir) {[dirArray addObject: file];} isDir = NO;} NSLog (@ "Every Thing in the dir: % @", fileList); NSLog (@ "All folders: % @", dirArray );