NSFileManager copyItemAtPath:toPath: takes two NSString's so you can't use an NSURL anyway. In fact nothing in that code needs an NSURL.
Get rid of that NSURL stuff (note: typed in mail) NSString *imagePath = [ [ [ self applicationSupportFolder ] stringByAppendingPathComponent:@"images" ] stringByAppendingPathComponent:fileName ]; then just use the imagePath. On 29-Aug-2010, at 5:23 PM, Amy Heavey wrote: > Thanks everyone, I've been looking at everything and still can't quite get my > head round it, basically all I want to do is copy a selected file to a new > location. > > I'm using a coredata app, so I was trying to follow the 'default' code > provided, but I'm compiling for 10.5 and it seems there's a bit of flux > between string based paths and urls. > > Is there sample code / tutorial somewhere I'm missing? > > This is what I've got at the moment, but it's still mixing URLs and strings, > I've tried just using strings, but the applicationSupportFolder returns a > string, which then is immutable so I can't add to it? > > - (IBAction)selectImageFile:(id)sender; > { > // Create the File Open Dialog class. > NSOpenPanel* openDlg = [NSOpenPanel openPanel]; > > // Enable the selection of files in the dialog. > [openDlg setCanChooseFiles:YES]; > > // process the files. > if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton ) > { > // Get an array containing the full filenames of all > // files and directories selected. > NSArray* files = [openDlg filenames]; > > // process file > NSObject *Product; > Product = [[Products selectedObjects] objectAtIndex:0]; > NSString* filePath = [files objectAtIndex:0]; > > NSString* fileName= [filePath lastPathComponent]; > NSURL* imagePath = [NSURL fileURLWithPath: [[self > applicationSupportFolder] stringByAppendingPathComponent: @"images"]]; > -->>Here are 2 warnings that NSURL may not respond to > stringByAppendingPathComponent > [imagePath stringByAppendingPathComponent:fileName]; > NSLog(@"Old Path is %@ New Path is %@", filePath, imagePath); > [[ NSFileManager defaultManager ] copyItemAtPath:filePath > toPath:imagePath error:nil]; > > > //[Product setValue:imagePath forKey:@"productImage"]; > > > } > > Many Thanks > > Amy > > > > On 29 Aug 2010, at 9:30AM, Graham Cox wrote: > >> >> On 29/08/2010, at 10:14 AM, Amy Heavey wrote: >> >>> I still get an error: >> >> >> On what line? >> >> Looking at the code you have mixed string paths and URLs. Pick one or the >> other and use it consistently. While string paths are becoming deprecated in >> favour of URLs, it might be easier to just use string paths initially to get >> it working and then convert to URLs throughout afterwards. >> >> For example, [NSOpenPanel filenames] is deprecated, as it returns the >> selected files as strings. Use [NSOpenPanel URLs] if you want to use URLs. >> Similarly for [NSFileManager copyItemAtPath:toPath:error] use [NSFileManager >> copyItemAtURL:toURL:error]. >> >> Mixing two different representations of a file path is what is causing you >> problems here. Be consistent. >> >> --Graham >> >> >> _______________________________________________ >> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) >> >> Please do not post admin requests or moderator comments to the list. >> Contact the moderators at cocoa-dev-admins(at)lists.apple.com >> >> Help/Unsubscribe/Update your Subscription: >> http://lists.apple.com/mailman/options/cocoa-dev/home%40willowtreecrafts.co.uk >> >> This email sent to h...@willowtreecrafts.co.uk > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org > > This email sent to r...@rols.org _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com