IOS: folder management, file operations, ios folder management operations
Native, do not know whether it will be used, the previous notes.
=============================== Folder management ======================== =
1. Obtain the Document Manager ticket
NSFileManager *fileManager = [NSFileManager defaultManager];
2. Use a manager to create a folder
// Path: name of the folder to be created. The folder name has no suffix [fileManager createDirectoryAtPath: path withIntermediateDirectories: YES attributes: nil error: & error]
3. Create a file
// FilePath: The file created in the previous folder, which is "xxx. xxx" data to be encoded [fileManager createFileAtPath: filePath contents: data attributes: nil]
4. Read File Information
// Returns the dictionary [fileManager attributesOfItemAtPath: filePath error: & error]
5. Read the dictionary information returned by the file
[infoDic objectForKey:@"NSFileSize"]
6. File Reading
6-1), Method 1:
// Read NSDataNSData * newData = [fileManager contentsAtPath: filePath]; // decode [[NSString alloc] initWithData: newData encoding: NSUTF8StringEncoding];
6-2), Method 2:
[[NSString alloc]initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
7. File Movement (cut and rename)
// The file name is suffixed with "xxx. xx" [fileManager moveItemAtPath: oldPath toPath: newPath error: & error]
8. File Replication
// The file name is suffixed with "xxx. xx" [fileManager copyItemAtPath: oldPath toPath: newPath error: & error]
9. delete a file
// The file name is suffixed with "xxx. xx" 1. First, check whether there is a file [fileManager fileExistsAtPath: oldPath] 2. Delete [fileManager removeItemAtPath: oldPath error: & error]
================================ File Operations ============================ =