try
set thedecision to "completed"
thedupcheck as alias
tell me to activate
set thedisplay to display dialog "An archive with the name \"" & thesourcename & "\" already exists in the destination" buttons {"Replace", "Rename", "Cancel"} default button "Replace"
try
if button returned of thedisplay is "Replace" then
set qthesourceitem to quoted form of (POSIX path of thesourceitem)
set qthedupcheck to quoted form of (POSIX path of thedupcheck)
do shell script "rm -r " & qthedupcheck
set qifolder to quoted form of (POSIX path of ifolder)
set thecmd to "mv " & qthesourceitem & " " & qifolder
do shell script thecmd
end if
end try
try
if button returned of thedisplay is "Rename" then
repeat
set qthesourceitem to quoted form of (POSIX path of thesourceitem)
set thenewname to my getname(thesourcename)
set thenewcheck to ifolder & ":" & thenewname
set qthenewcheck to quoted form of (POSIX path of thenewcheck)
set qifolder to quoted form of (POSIX path of ifolder)
try
thenewcheck as alias
on error e
set thecmd to "mv " & qthesourceitem & " " & qthenewcheck
do shell script thecmd
set thecmd to "mv " & qthenewcheck & " " & qifolder
do shell script thecmd
exit repeat
end try
end repeat
end if
end try
on error e
--say 9
set thedecision to "proceed"
end try
--say 10
tell me to activate
display dialog thedecision
return thedecision
end dupcheck
on getname(thesourcename)
try
set AppleScript's text item delimiters to "."
set thenametext to text items 1 thru -2 of thesourcename
set thenameextension to last text item of thesourcename
set thenametext to thenametext as string
set AppleScript's text item delimiters to ""
on error e
--for folders
set thenametext to thesourcename
end try
tell me to activate
set thenewname to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer thenametext)
try
set thenewname to thenewname & "." & thenameextension
on error e
--for folders
set thenewname to thenewname
end try