Re: NSFileManager problem
Re: NSFileManager problem
- Subject: Re: NSFileManager problem
- From: Shane Stanley <email@hidden>
- Date: Mon, 26 Oct 2015 21:50:31 +1100
On 26 Oct 2015, at 8:01 PM, Takaaki Naganoya <email@hidden> wrote:
Already file exists in the target folder.
OK, two options. You can just delete the existing file first, or you can replace it. The delete option:
set {theResult, theError} to (defM's moveItemAtURL:fromPath toURL:toPath |error|:(reference)) if not theResult as boolean then if (toPath's checkResourceIsReachableAndReturnError:(missing value)) as boolean then -- it already exists, so try deleting defM's removeItemAtURL:toPath |error|:(missing value) -- try moving again set {theResult, theError} to (defM's moveItemAtURL:fromPath toURL:toPath |error|:(reference)) end if end if
The replace option is a bit more complicated, but does it in a way that there is no chance of data loss. So:
set {theResult, theError} to (defM's moveItemAtURL:fromPath toURL:toPath |error|:(reference)) if not theResult as boolean then if theError's code() = (current application's NSFileWriteFileExistsError) then -- it already exists, so try replacing set {theResult, theError} to defM's replaceItemAtURL:fromPath withItemAtURL:toPath backupItemName:(missing value) options:(current application's NSFileManagerItemReplacementUsingNewMetadataOnly) resultingItemURL:(missing value) |error|:(reference) end if end if
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden