I would say rename the new destination file if you think you should
keep the old one around.

However, if it's always the case that the new file should replace the
old one when it finishes downloading, then you should save the new
file under a temporary name and use -[NSFileManager
replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:].
Look at the documentation for that. I think you'll also want to
research using -[NSFileManager
URLForDirectory:inDomain:appropriateForURL:create:error:] with
NSItemReplacementDirectory.

On Tue, Mar 24, 2015 at 7:55 PM, Daryle Walker <dary...@mac.com> wrote:
> Right now, my command-line tool errors out if the destination filename, 
> chosen automatically from the NSURLResponse object, already exists in the 
> working directory. Should I keep it that way, or put the new file there 
> anyway? If the latter, this involves doing something to the previous file 
> with that name (or keeping it the same and renaming the new file instead). 
> Should I delete the old file (causing problems if transferring the new one 
> fails), try replacing (does it work across volumes), or trashing the old file 
> (does this send the instant-delete GUI alert if it happens while current 
> Trash items are emptied)?
>
> If renaming is the answer, is there any sample code to do this safely, taking 
> care of all cases?  (For example, replacement name already taken, or adding 
> an extension if the file doesn’t start with one, etc.)
>
> —
> Daryle Walker
> Mac, Internet, and Video Game Junkie
> darylew AT mac DOT com
>
> _______________________________________________
>
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com
>
> This email sent to stephen.but...@gmail.com

_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to