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.