File management class Nsfilemanager common operations

Source: Internet
Author: User
Tags file copy

1. Create a File Manager

Nsfilemanager *FM = [Nsfilemanager Defaultmanager];

2. Traverse the directory in a shallow degree

-(Nsarray *) ContentsofdirectoryatpatH: (NSString *) path error: (NSERROR * *) error

3. Deep Traverse Directory

-(Nsarray *) SubpathsofdirectoryatpatH: (NSString *) path error: (NSERROR * *) error

4. Get the current directory

-(NSString *) Currentdirectorypath

5. Change the current directory

-(BOOL) Changecurrentdirectorypath: (NSString *) path

6. Enumerate Directory Contents

-(Nsdirectoryenumerator *) Enumeratoratpath: (NSString *) path

7. Create a Directory

-(BOOL) Createdirectoryatpath: (NSString *) path withintermediatedirectories: (BOOL) createintermediates Attributes: (nsdictionary *) attributes Error: (NSERROR *) error

8. Create a file

-(BOOL) Createfileatpath: (NSString *) path contents: (NSData *) Contents attributes: (nsdictionary *) attributes

9. Copying files

-(BOOL) Copyitematpath: (NSString *) Srcpath Topath: (NSString *) Dstpath Error: (NSERROR *) error

10. Delete Files

-(BOOL) removeItemAtPath: (NSString *) path error: (NSERROR * *) error

11, directory/File copy

-(BOOL) Copyitematpath: (NSString *) Srcpath Topath: (NSString *) Dstpath Error: (NSERROR *) error

12. Move/rename files or directories

-(BOOL) Moveitematpath: (NSString *) Srcpath Topath: (NSString *) Dstpath Error: (NSERROR *) error

13. Does the test file exist?

-(BOOL) Fileexistsatpath: (NSString *) path

14. Get file information (properties and permissions)

-(Nsdictionary *) Attributesofitematpath: (NSString *) path error: (NSERROR * *) error

15. Reading data from a file

-(NSData *) Contentsatpath: (NSString *) path

16. Compare the contents of two files

-(BOOL) Contentsequalatpath: (NSString *) path1 Andpath: (NSString *) path2

17. Whether the test file exists, and whether it can perform read operation

-(BOOL) Isreadablefileatpath: (NSString *) path

18. Whether the test file exists, and whether it can perform write operation

-(BOOL) Iswritablefileatpath: (NSString *) path

Second, the file operation class Nsfilehandle common operation:

1. Open file with read-only mode

+ (ID) filehandleforreadingatpath: (NSString *) path

2. Open file with write-only method

+ (ID) filehandleforwritingatpath: (NSString *) path

3, read-write mode open file

+ (ID) FILEHANDLEFORUPDATINGATPath: (NSString *) path

4. Read from the current position of the file to the end

-(NSData *) readdatatoendoffile

5. Read the contents of fixed bytes from the current location of the file

-(NSData *) Readdataoflength: (nsuinteger) length

6. Return all available data

-(NSData *) availabledata

7. Write files

-(void) WriteData: (NSData *) data

8. Locate the tail of the file

Long long) Seektoendoffile

9. Navigate to the location specified in the file

-(voidlonglong) offset

10. Get the current file offset

Long long) Offsetinfile

11. Set the length of the file to offset bytes

-(voidlonglong) offset

Close File

-(void) CloseFile

P.s. (In a network socket) the object that is initialized by Initwithfiledescriptor requires an explicit call to this method, and the object created by the other method automatically opens the file, which is automatically closed when the object is destroyed and does not need to be explicitly called.

File management class Nsfilemanager common operations

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.