Re: using 'cp' with NSTask
Re: using 'cp' with NSTask
- Subject: Re: using 'cp' with NSTask
- From: Les Producteurs <email@hidden>
- Date: Fri, 28 Jan 2005 17:44:35 +0100
If you still want to use NSTask look at his line :
NSArray *args = [NSArray arrayWithObjects:copyPath, targetPath];
must be :
NSArray *args = [NSArray arrayWithObjects:copyPath, targetPath,nil];
Using NSFileManager is trivial :
[[NSFileManager defaultManager] copyPath: copyPath toPath: targetPath handler:nil];
JYC
On 28 janv. 05, at 17:15, Peter Browne wrote:
I want to be able to copy an image file to a new location. There is an NSImageView that the user can load a picture into, and I want the user to be able to save this image to a new location. I've tried doing this using NSTask and 'cp', passing the file path (taken from the open panel when the user loads an image into the view) and the target path as arguments. However, when it tries to run 'cp' the program chokes. Here is the relevent code:
When the open panel is closed:
if (returnCode == NSOKButton) {
mapPath = [openPanel filename]; <- mapPath is an NSString
[self setFilePath:mapPath]; <- sets the filePath variable to the result of the open panel
NSLog(@"map file path is now %@", [self filePath]);
newMap = [[NSImage alloc] initWithContentsOfFile:mapPath];
[self setImage:newMap];
[newMap release];
}
This is the 'getting' method to access the filePath from other classes
- (NSString *)filePath // Used for getting to path to the image so it can be copied
{
return filePath;
}
When the users clicks save:
NSString *copyPath = [mapView filePath];
NSString *targetPath = [NSString stringWithFormat:@"%@/Desktop/blah.pdf", NSHomeDirectory()];
NSLog(@"Going to copy from %@ to %@.", copyPath, targetPath);
NSArray *args = [NSArray arrayWithObjects:copyPath, targetPath];
// the task to handle copying of the map image
NSTask *cp = [NSTask launchedTaskWithLaunchPath:@"/bin/cp" arguments:args];
[cp launch];
Any ideas? Thanks in advance, Peter _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden