IOS Move File Method Rollup _ios

Source: Internet
Author: User

This section of Objective C code is used to move files under the specified path

Copy Code code as follows:

if ([FileManager copyitematpath:@ "FilePath1"
topath:@ "FilePath2" Error:null]) {
NSLog (@ "Copied successfully");
}

Method Two :

Use Nsfilemanager:
Get the path to your document and your cached path. Traverse all the files and move them using Nsfilemanager

Copy Code code as follows:

-(void) Movealldocs {
Nsfilemanager *filemanager = [Nsfilemanager Defaultmanager];
Nserror *error = nil;
NSString *sourcedirectory = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, NSUserDomainMask, YES) Lastobject];
NSString *destinationdirectory = [Nssearchpathfordirectoriesindomains (nscachesdirectory, NSUserDomainMask, YES) Lastobject];
Nsarray *contents = [FileManager contentsofdirectoryatpath:sourcedirectory error:&error];
For (NSString *sourcefilename in contents) {
NSString *sourcefile = [Sourcedirectory stringbyappendingpathcomponent:sourcefilename];
NSString *destfile = [Destinationdirectory stringbyappendingpathcomponent:sourcefilename];
if (![ FileManager moveitematpath:sourcefile topath:destfile Error:&error]) {
NSLog (@ "error:%@", error);
}
}
}

Method Three :

Fcfilemanager is an IOS file management tool built on top of Nsfilemanager, simplifying file management. It provides a number of static methods for performing the most commonly used operations with a few lines of code. It works as a default file directory, allowing you to use relative paths, but it can work easily in any other directory.

Move File:

Copy Code code as follows:

[Fcfilemanager moveitematpath:@ "test.txt" topath:@ "Tests/test.txt"];

Remove file:

Copy Code code as follows:

Remove file at the specified path
[Fcfilemanager removeitematpath:@ "test.txt"];

The above mentioned is the entire content of this article, I hope you can enjoy.

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.