Copying folders from a server...

Hey there-

First off, I’m an Applescript beginner. Here’s a scenario I’d like to try and resolve with an Applescript.

I’d like to be able to copy a folder (of scans), and then trash, from a server. What I have so far is this:

set server to choose folder with prompt "Please choose a server." --Select hard drive the scan has been saved to, and call it "server" 
set destination to choose folder with prompt "Please choose a destination folder." -- Select work folder on the hard drive the scan will be copied to, and call it "destination" 
set file_name_entry to display dialog ¬
	"Please enter the folder name:" default answer ¬
	" " with icon note buttons {"Cancel", "Continue..."} default button "Continue..." --Asks imager to Input the name of the scan folder, and calls it "file_name_entry" 
set file_name to text returned of file_name_entry -- Designates the text that was entered to be the file name. 
set button_name to button returned of file_name_entry -- Designates the button that was chosen to be called "button_name. 
if button_name is "Continue..." then
	tell application "Finder"
		activate
		select folder file_name of folder " Scans" of disk server
		copy selection to folder destination
		delete selection
	end tell
end if

What this does is it asks user to select the server, and then a destination folder on their hardrive. Then the user inputs the name of the folder. It will copy the folder and then trash it from the server. This script works fine, as long as the folder they want to copy is in a specific folder (" Scans") on the server. What I would like to do is have it pull the folder from any (unknown) folder from the server.

Can I get the script to find and copy folders or files anywhere on a server (not a specific folder)?

Thanks in advance.

To find the folder by name, you’ll probably have to use an OSAX. You can try examing the Finder’s “entire contents” of the server for the named folder, but entire contents is notoriously unreliable on a disk of any size.

I’d suggest Tanaka’s OSAX, which would work like this:

MT List Folders server name contains file_name return as string with sub folders

Keep in mind that you might find more than one folder using file_name, so if there’s more than one item in the result, you might want to use a choose from list dialog.

When your script tells the finder to “copy” the folder, does that work? I could’ve sworn that the magic word was duplicate, not copy.

At some point in your applescripting career, you’ll learn that it’s usually not necessary to “select” a file or a folder before doing something with it. Once you have the full path to the target folder, just duplicate (or copy) it to the new disk and then delete it. No selection needed.

Hope this helps…

Hi Rob-

Thanks for the help. I’ll have to play with this more to understand it better.

The reason my script said “copy,” and “selected” the folder, was only because sometimes I ‘record’ parts of a script I’m trying to make to see what code it gives me automatically. I can then take that and piece it apart to see how it works. But anyway, that’s what It gave me automatically, so, not knowing any better, I went with it.

Thanks.

Like Carl, I would like to copy files from non-preset locations on my server.

Instead of having the copy-to locations set by the user I have the folders created by the script with information from FMP fields info.

For copying the folders, I can make the script copy them from the top most level of the server, but the folders I need to copy are scattered throughout secondary folders (in the form of weeks). Can the MT List Folders from Tanaka’s OSAX work here. I am trying to use Tanaka’s OSAX, but I still don’t completely understand what to do. This is what I have:
MT List Folders “My Server” contains myvariable return as string with sub folders
myvariable is set earlier in the script from a FMP field. What does “return as string with sub folders” do? Does it bring up a list of the folder/file with the name “myvariable” This is where I think I am most confused.

I am not currently worried about multiple folders of the same name being found yet - I’ll work on that when I get the copy part down. And I would like this script to be as hands-off for the user as possible.

Thank you ahead of time.

As for my first script, it works! Thank yous to Andreas and mac_guy for their help. You helped make an 8 hour process happen in 2 1/2 minutes! Now to make it better!