Application of NSFileManager and NSFileManager
SingletonIn a file, all files can be shared only once. The created addresses are the same NSFileManager * manager = [NSFileManager defaultManager]. is a singleton NSFileManager * manager = [NSFileManager defaultManager];
// Determine whether a file or folder exists
// Parameter a indicates whether the file is a directory. If yes is returned, no is returned.
// Parameter B indicates whether the folder exists
BOOL;
BOOL B = [manager fileExistsAtPath: @ "/Users/zhangyunjiang/Desktop/Video 1/ .mp4" isDirectory: & a]; NSLog (@ "% d", B, a); // get the attributes of a file or folder
NSDictionary * dic = [manager attributesOfItemAtPath: @ "/Users/zhangyunjiang/Desktop/Video 1/ .mp4" error: nil]; NSLog (@ "% @", dic ); // get all files in the file (Disadvantage: cannot get the data in the file)
NSArray * arr = [manager contentsOfDirectoryAtPath: @ "/Users/zhangyunjiang/Desktop/Video 1" error: nil];
NSLog (@ "% @", arr );
// Use subpathsAtPath to obtain the data in the file
NSArray * arr1 = [manager subpathsAtPath: @ "/Users/zhangyunjiang/Desktop/Video 1"]; NSLog (@ "% @", arr1 ); // copy BOOL a = [manager copyItemAtPath: @ "/Users/zhangyunjiang/Desktop/c Language/app c exercise/app" toPath: @ "/Users/zhangyunjiang/Desktop/untitled folder" error: nil]; NSLog (@ "% d", a); // Delete BOOL B = [manager removeItemAtPath: @ "/Users/zhangyunjiang/Desktop/zyj" error: nil]; NSLog (@ "% d", B); // move (CUT) BOOL c = [manager moveItemAtPath: @ "/Users/zhangyunjiang/Desktop/untitled Folder/app" toPath: @ "/Users/zhangyunjiang/Desktop/zyj" error: nil]; NSLog (@ "% d ", c); // create the folder BOOL a = [manager createDirectoryAtPath: @ "/Users/zhangyunjiang/Desktop/zyj/jiuh/sdgre/fsdg" withIntermediateDirectories: YES attributes: nil error: nil];
NSLog (@ "% d", );
// Create the file BOOL B = [manager createFileAtPath: @ "/Users/zhangyunjiang/Desktop/frty.txt" contents: nil attributes: nil]; NSLog (@ "% d ", B );