Reputation: 672
How can move folder from one location to another location. I have a folder inside Library/data, i need to move to Documents/data. Is it possible ?
Thanks in advance
Upvotes: 0
Views: 228
Reputation: 998
NSArray *pathDirectory= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"toFolderName"];
Use following line if you want to move a file from in document directory
NSString *fromPath=[[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"fromFolderName"];
if you want to move from bundle then use following
NSString *frompath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"fileType"];
NSError *Error;
// If you want to add any subPath to destination folder add else commit following line
NSString *toPath = [[pathSong objectAtIndex:0] stringByAppendingPathComponent:@"toSub"];
//DELETE THE FILE AT THE LOCATION YOU'RE COPYING TO
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:toPath error:NULL];
if([[NSFileManager defaultManager]copyItemAtPath:from toPath:toPath error:&Error]==NO){
// do somthing on succes if you want
}
Upvotes: 1