AppleScript to copy files even if error occurs

Discussion in 'Mac Programming' started by textandyp, Jul 15, 2010.

  1. textandyp macrumors newbie

    Joined:
    Jul 15, 2010
    #1
    So I work for my school's computer repair desk and am trying to write a script so that we can choose a file to copy and have it continue to copy even if it gets an error (I believe it's error -36). I know that this can be done in Terminal, but I'm pretty sure the point of AppleScript (even advice for Automator is welcome) is to make life easier. I have this so far:

    Code:
    [FONT="Verdana"]display dialog "Do you want to copy a Folder or a File?" buttons {"Cancel", "Files", "Folders"} default button "Folders"
    copy the result as list to {buttonpressed}
    try
    	if the buttonpressed is "Files" then moveFile()
    	
    	if the buttonpressed is "Folders" then moveFolder()
    end try
    
    on moveFolder()
    	tell application "Finder"
    		set sourceFile to choose folder with prompt "Choose a Folder to Copy:"
    		set targetFolder to choose folder with prompt "Select Destination"
    		try
    			move sourceFile to targetFolder
    		on error errMsg number errNum
    			display dialog "Error: " & errNum & return & errMsg
    		end try
    		update targetFolder
    	end tell
    end moveFolder
    
    on moveFile()
    	tell application "Finder"
    		set sourceFile to choose file with prompt "Choose a Folder to Copy:"
    		set targetFolder to choose file with prompt "Select Destination"
    		try
    			move sourceFile to targetFolder
    		on error errMsg number errNum
    			display dialog "Error: " & errNum & return & errMsg
    		end try
    		update targetFolder
    	end tell
    end moveFile[/FONT]
    I am no expert at AS, and would welcome any changes that would make this easier if you think it would help. I have borrowed most of this from another form I found, but would like to make sure that it copies the file or folder, skipping over any files that give an error.
    thanks!
     
  2. mrbash macrumors 6502

    Joined:
    Aug 10, 2008
    #2
    Error -36 is a File System error. Apple's docs state that you should either try using a different destination device, or reboot the system with extensions turned off and try copying the file.

    More than likely the source file is corrupted so there is no guarantee that the copy will be any good.

    So essentially, AppleScript is not going to help you, neither is a terminal. They are copying the same file the same way--by making the same system call.

    Your best bet is to try repairing the source and then copying the file after rebooting with all extensions turned off.

    Here is a link to Apple's Support doc.


    Just out of curiosity, are you a volunteer at your school's repair desk?
     

Share This Page