IOS: folder management, file operations, ios folder management operations

Source: Internet
Author: User

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 ============================ =

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.