I'm am trying to make a very simple rsync program with a user interface. All I need is the ability to drag and drop two file paths so one will copy to the other. For now I'm just trying to copy one file on my desktop to a folder on the desktop and that won't even work. I'm using text fields titled "source" and "destination" to take away the file paths I drag into them. I have the following code:
#import "AppController.h"
@implementation AppController
@synthesize source = _source, destination = _destination;
-(IBAction)sync:(id)sender
{
NSFileManager *manager = [[NSFileManager alloc] init];
//NSURL *source = [NSURL fileURLWithPath:@"/Users/crashprophet/Desktop/Time Out Tot Schedule.doc"];
// NSURL *destination = [NSURL fileURLWithPath:@"/Users/crashprophet/Desktop/untitled f older 2"];
NSURL *source = [NSURL URLWithString:self.source.stringValue];
NSURL *destination = [NSURL URLWithString:self.destination.stringValue];
[manager copyItemAtURL:source toURL:destination error:nil];
NSLog(@"The source path is %@ and the destation path is %@",source, destination);
NSLog(@"Got here!");
}
@end
Any ideas?
You need to use fileURLWithPath: if your strings look like the ones in your comments. Also, the destination path can't just be a folder, it needs a file name on the end -- you can use the same file name as the original, or you can give it a new one. From the docs on the copy method you're using:
"dstURL The URL at which to place the copy of srcURL. The URL in this parameter must not be a file reference URL and must include the name of the file in its new location. This parameter must not be nil."