Continue Copying on Error

Hello all,

I am new to AppleScript so any help is appreciated. =)

I have written a script that will make a backup copy of all the files in certain directories of our server by copying them to another volume on the server. My only problem is that if the script runs across a file that is in use or otherwise uncopyable, the script stops copying at that point. Is there a way that I can get the script to continue copying even though it runs across an error?

Currently, I am using the “duplicate” command to do the dirty work in my script. Is there some attribute I can set to make the script do what I want it to do (e.g., duplicate “with continue” or something?)

If it would be helpful, I will be happy to post my script here. It is rather short (about 40 lines.)

Thanks, Eric Richard

Marc obviously assumed that you knew the proper syntax:

        -- statement which may cause error
    on error
        -- you put nothing here so the script does nothing with an error
    end try

PS: There is an inherent risk in that too-simple bit of code. Better would be:

    -- statement which may cause error
on error number errNum
    -- If errNum is not what you expect then take some action (e.g. 'display dialog')
    -- i.e. implicit that if errNum IS what you expect then do nothing
end try
set list_of_jobs to list folder "hard disk:my folder:" as list without invisibles
repeat with job in list_of_jobs --this is the start of the repeat
copyfile "hard disk:my folder:" & job to "hard disk:another folder:" replacing yes
end try
end repeat

it works by setting the variable listofjob to the contents of the folder you want to copy from.

the repeat works by setting the variable job to the top job of the list and then copying the file to the place you want. The repeat then repeats and the variable job then becomes the next job on the list etc. You might need jons commands in the additions folder to get this to work

let me know if this works

Alright, I’ll give that a try… A couple of questions,though: Do I need to define the variable “job” before using it? and, What are Jons commands?

As it stands now, my script tries to copy the folders as a whole. I thought about doing a list, but how do I deal with subfolders? (There are lots of them!) From what I’m hearing, though, listing the files to be backed up seems to be the way to go.
Thanks for your help,

You certainly could continue with variations on “list folder” but if you have a look at the Akua dictionary entry for “the entries in” I think that all your questions will be answerd. And it will be easier, and more reliable, and faster. And if you haven’t already got Akua then get it from the Scripting Additions section of this site.

A related question, going back to Rick Kenny’s post…

Considering this statement:

set list_of_jobs to list folder "hard disk:my folder:" as list without invisibles

Would this just list the elements (files and folders) of “my folder”, or would it list the full path names of everything in “my folder” and all subdirectories? What I really need is a way to list the full pathnames (or, at least, list all of the files) so that “on error” I can skip the copying of just one file instead of skipping the rest of the files in that subfolder.