simple file copy problem

I’m becoming a bit exasperated with what should be a trivial task. I have a group of files and folders that I want to copy to a network drive. I searched the forum for examples and found lots. Unfortunately, I cannot get any of them to work. Here is my most recent attempt, inside a ‘tell’ block for ‘Finder’:


		repeat with t_file in source_files
			duplicate file t_file to folder_name
		end repeat
		repeat with t_folder in source_folders
			duplicate folder t_folder to folder folder_name
		end repeat

The error I get is “Cant’ set folder to file (item 1 of {<blah, blah>}).” Can someone tell me how to fix this? TIA.

It’s difficult to determine what’s wrong without knowing what the variables hold. Can you post all of the relevant code? The blah blah part of the error message might also be helpful. Your report is similar to going to an auto mechanic and advising him/her that the blah blah is making an awful noise. :wink:

– Rob

Thanks for the reply.

As a beginner, I made the assumption (shame on me) that it was my syntax or usage. I take it from your response that it might be my variables. I think this covers it (unrelated code was omitted for clarity, I hope):


set server_label to "aimaudit Backup"
set source_files to {"4D Data Mac:aimauditDEV007.data", "4D Data Mac:aimauditDEV007.d2", "4D Data Mac:aimauditDEV007.d3", ¬
	"4D Server:Aim Operations/aimaudit.4db", "4D Server:Aim Operations/cert.pem", ¬
	"4D Server:/Aim Operations/key.pem"}
set source_folders to {"4D Server:Aim Operations/MAC4DX", "4D Server:Aim Operations/WIN4DX", ¬
	"4D Server:Aim Operations/Web Root"}
set folder_name to "aimauditBU" & (year of (current date) as string) & month_number & (day of (current date) as string) & ¬
	"_" & hrmin

<inside 'tell'>
set new_folder to (make folder at server_label)
		set the name of new_folder to folder_name
		repeat with t_file in source_files
			duplicate file t_file to folder folder_name
		end repeat
		repeat with t_folder in source_folders
			duplicate folder t_folder to folder folder_name
		end repeat

To a Unix admin, this seems like it should be a trival task but Applescript seems like a black art to me so far. Documentation is … (well, I don’t want to start a religious war).

As for the error message, it won’t let me cut & paste but substitute the value of ‘folder_name’ for the first <blah, blah> and the list ‘source_files’ for the second <blah, blah>.

Does this work?

set server_label to "aimaudit Backup"
set source_files to {"4D Data Mac:aimauditDEV007.data", "4D Data Mac:aimauditDEV007.d2", "4D Data Mac:aimauditDEV007.d3", ¬
	"4D Server:Aim Operations/aimaudit.4db", "4D Server:Aim Operations/cert.pem", ¬
	"4D Server:/Aim Operations/key.pem"}
set source_folders to {"4D Server:Aim Operations/MAC4DX", "4D Server:Aim Operations/WIN4DX", ¬
	"4D Server:Aim Operations/Web Root"}
set folder_name to "aimauditBU" & (year of (current date) as string) & month_number & (day of (current date) as string) & ¬
	"_" & hrmin

tell application "Finder"
	set new_folder to (make new folder at folder server_label with properties {name:folder_name})
	repeat with t_file in source_files
		duplicate file t_file to new_folder
	end repeat
	repeat with t_folder in source_folders
		duplicate folder t_folder to new_folder
	end repeat
end tell

– Rob

No but the error changed on the ‘duplicate’. Now I get, “A descriptor type mismatch occurred.”

Maybe this will fix it.

tell application "Finder"
	set new_folder to (make new folder at folder server_label with properties {name:folder_name})
	repeat with t_file in source_files
		duplicate file t_file to folder new_folder
	end repeat
	repeat with t_folder in source_folders
		duplicate folder t_folder to folder new_folder
	end repeat
end tell

– Rob

I never took ‘folder’ out when I made your change. I didn’t see that change. When I took it out it started working (this is a black art).

Now we are at the next layer of the onion. After a while I get, “AppleEvent timed out.” But the copy continues until the first one completes then the ‘repeat’ is terminated. I guess there must be some parameter to set that tells ‘finder’ the copy will take a long time?

Sheesh! This really is rocket science. :?

Just to explain the original problem… in your original code you had the line:

set the name of new_folder to folder_name 

where ‘folder_name’ is a list. So now ‘new_folder’ is a copy of that list.

When you try to:

duplicate file t_file to folder folder_name 

You’re telling the finder to copy a file to a list, which clearly can’t work.

Rob’s fix is to extract the name of the folder from the list and pass that into the duplicate command.

As for the timeout issue, just enclose the relevant parts in a ‘with timeout’ block. This overrides AppleScript’s normal timeout function to allow high-latency tasks to be performed:

...
with timeout of 600 seconds -- the following code can take 10 minutes to execute
   duplicate file t_file to folder folder_name
end timeout

Thanks. I guess that is what happens when a beginner has to learn by extracting code from examples. I obvioulsy need to understand types better.

Thanks to all that replied but it looks like there is yet another layer to this onion.

Please note the list ‘source_files’ in an earlier post. The first 3 ‘duplicate’ fine. The 4th item fails with a type mismatch error. The only difference being the file is in a sub-folder. I’m stumped again. Obviously this is still black magic to me. TIA.

I wondered about that earlier. I’ll bet the failure is related to the slash in the path.

– Rob

How else do you specify the path?

If ‘Aim Operations’ is a folder/directory:

“4D Server:Aim Operations:WIN4DX”

– Rob

Oh. I thought the ‘:’ was for disks and ‘/’ for folders. Too much Unix ingrained.

That didn’t help, however. Same error.

I suspect a path problem. You can use the following to grab the correct paths to files and folders. The path will be placed on the clipboard for easy pasting into your script.

-- for files
set the clipboard to (choose file) as text

-- for folders
set the clipboard to (choose folder) as text

– Rob

Thanks for the suggestion but that only showed my path is correct. I think the problem may be the destination. Is it trying to duplicate JUST the file or is it trying to duplicate the folder AND file? That folder does not exist on the destination share. I guess I can create it adn then try again.

Could you post your current code and state where it is failing? We’ve tried so many things that I don’t know what you are using. FYI, in case you haven’t noticed, when you run the script in Script Editor and it errors, the troublesome code is generally highlighted.

– Rob

Rather then refer you to the previous code I posted I’ll repost the relevant code since you folks, thankfully, had me change it a bit:


set source_files to {"4D Data Mac:aimauditDEV007.data", "4D Data Mac:aimauditDEV007.d2", "4D Data Mac:aimauditDEV007.d3", ¬
	"4D Server:Aim Operations:aimaudit.4db", "4D Server:Aim Operations:cert.pem", ¬
	"4D Server:Aim Operations:key.pem"}
set source_folders to {"4D Server:Aim Operations:MAC4DX", "4D Server:Aim Operations:WIN4DX", ¬
	"4D Server:Aim Operations:Web Root"}
set new_folder to (make new folder at folder server_label with properties {name:folder_name})

<inside the 'tell'>
repeat with t_file in source_files
			with timeout of 600 seconds
				duplicate file t_file to new_folder
			end timeout
		end repeat
		repeat with t_folder in source_folders
			with timeout of 600 seconds
				duplicate folder t_folder to new_folder
			end timeout
		end repeat		

In summary, it is the first ‘duplicate’ that gets the error when it tries to use item 4 in the ‘source_files’ list. I haven’t made it to the second ‘repeat’ yet so I suspect there are a few more layers of this onion left. :cry:

P.S. I tried adding the line:


make new folder at new_folder with properties {name:"Aim Operations"}

after the ‘set new_folder’ to create it on the destination share thinking it was failing because it was copying a path that includes a subfolder that didn’t exist. But I didn’t get very far since that line gets a type mismatch error.

I just noticed a couple of things that I hadn’t noticed earlier:

  1. Files 4 through 6 are on a different volume than files 1 through 3.
  2. Files 4 through 6 are being duplicated to their host.

I suspect that one or both of these issues, or maybe a permissions problem, is causing the script to fail but I don’t have enough experience in scripting a networked environment to troubleshoot it. :?

– Rob