little help with move files & delete script.

Hello,
I’m (very) new at applescript, and I’m managed to piece this together from stuff I’ve found. It works the way it is, just not as efficiently as it probably could. What I seek to do is have the script move all the files from the folder it is attached to, into another designated folder. So this one copies, then deletes. The problem I’ve encountered is that the files that will be dropped into this hot folder are going to be folders full of thosands of files and gigs of data, over a network connection. So often the copy can take an hour or two for all the files to arrive. I found initially that the delete was working too quickly, before all the files were copied. So I added a delay of an hour as a test. But then I noticed during the test that my ‘system event’ thread usage was up around 80%, slowing down the computer while it counts to an hour before it deletes the files. So my question; how would I ask the script to instead of delaying, to check first and compare that all the files in folder A match folder B, before allowing it to delete folder A and its enclosing files. Thanks for any help!

on adding folder items to this_folder after receiving these_items
 tell application "Finder"
  set the destination_folder to folder "ToHere:" as alias
  set the destination_directory to POSIX path of the destination_folder
 end tell
 repeat with i from 1 to number of items in these_items
  set this_item to item i of these_items
  set the item_info to info for this_item
  if this_item is not the destination_folder then
   set the item_path to the quoted form of the POSIX path of this_item
   set the destination_path to the quoted form of ¬
    (destination_directory & (name of the item_info))
    do shell script ("/usr/bin/ditto -rsrc " & item_path & " " & destination_path)
    delay 3600    
do shell script ("rm -fR " & item_path)
   end if
  end repeat
end adding folder items to

Greg:

Have you tried simply moving the files, instead of copying and deleting?

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		set the destination_folder to folder "ToHere:" as alias
		set the destination_directory to POSIX path of the destination_folder
	end tell
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		if this_item is not the destination_folder then
			set the item_path to the quoted form of the POSIX path of this_item
			set the destination_path to the quoted form of ¬
				(destination_directory & (name of the item_info))
			do shell script ("mv " & item_path & " " & destination_path)--Moves the file instead of copying
			--delay 3600--should not need
			--do shell script ("rm -fR " & item_path)--should not need
		end if
	end repeat
end adding folder items to

I have not tried that… I thought about it, but figured the same issue would apply, that all the files in the directory that is being placed in the hotfolder would not have arrived yet, and the script would already be trying to move them out. So for example a folder inside a folder with files in it. The mv script would move that inside folder quickly potentially before all the files had landed in it. Thus causing a copy error.
I’ll give it a shot though, thanks for the response.
G.

Hey,
I tried it out… seems to have worked! (thx) the files don’t even appear in the hot folder, its fairly instantaneous, and doesn’t disrupt the copy error.
One more question for you. With the ditto command I was using before, it has the -rsrc flag on it to ensure the mac data/resource fork integrity. Do you know if mv has a similar flag. The reason I require this, is that my ultimate destination for the moving files is to a UDF format via an NFS share.
Thanks again,
G.

According to my text, [mv] does NOT preserve the resource forks or HFS metadata. For that, you are directed to use [MvMac], which is located in your Developer Tools. You must specifiy the path in this manner:

do shell script "/Developer/Tools/MvMac "& source &" "& target

Additionally, you must have installed your Developer Tools first.

I just did some reading on MvMac, thanks for that info BTW.
I found this…
As of Mac OS X 10.4, the mv command preserves metadata and resource forks
of files on Extended HFS volumes, so it can be used in place of MvMac.
The MvMac command will be deprecated in future versions of Mac OS X.

For my purposes mv should work great (the Xserve I intend to use it upon is 10.4).

Thanks for all your help, I appreciate the assistance greatly!
Cheers,
Greg.

Ammendment: Just found another tidbit of info that might be relevant to pre 10.4 users
MvMac - BUGS: Currently doesn’t work across volumes/filesystems.
but on 10.4 mv does work.

Ok, just tried out the script on my Xserve, it worked mostly… Except it (mv on 10.4) didn’t preserve the resource forks across filesystems as advertised. All the fonts and images became “unix executables”.
Hmm, I guess I could try installing the developer tools on the server and see if MvMac will do it, if not, back to ditto and deleting.

what about rsync -E ?