Re: using 'cp' with NSTask
Re: using 'cp' with NSTask
- Subject: Re: using 'cp' with NSTask
- From: James Andrews <email@hidden>
- Date: Fri, 28 Jan 2005 11:46:12 -0500
Dude,
Don't use NSTask for that. Use NSFileManager. It's 3 lines of code and it will use less overhead.
-james
On Jan 28, 2005, at 11:15 AM, 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