Help please with folder/file moving Deleting headache!!!

Hi

I have started to create a script which moves files/folders from one drive to another, the script checks a chosen folder on drive “A” for files which have the same names as files on a chosen folder on drive “B” and then proceeds to move/copy the files/folders it finds that don’t have the same names in to the other folder.
I can do this bit okay!!
But because this is working across drives it doesn’t move it copies the item’s so the items which have been moved are still left in the original folder"A" i want to delete these items but still leave the one’s with the same names in both folders"A’ & “B” its’s the delete bit i can’t get!!
Sometimes i’ve had the odd file delete but can’t get it to delete more than one.

Here is the script i have so far, it is set up like this cause i have done a mini mock up on my desktop before i move it on to the computer where it will be used hence the reason i have “duplicate” to recreate the files being left on “A”

tell application "Finder"
	set x to path to folder "A" on a mounted drive
	set y to path to folder "B" on a mounted drive
	tell application "Finder"
		count of item (x as Unicode text)
		set d to result
	end tell
	repeat with i from 1 to d
		set e to (name of item i of x)
		set e to e as string
		if not (exists the folder e of alias y) then
			display dialog "the file" & space & e & space & "doesn't exist in volume y so i will move it there" as string
			set |move the files| to duplicate item e of folder x to folder y
		end if
	end repeat
end tell

Hi, Pidge1

Somehow, these two sentences don’t compute. You copy files to ‘volB’ from ‘volA’ using a move command. You want to delete them, but leave them in both folders. :confused:

BTW:


set f to (choose file) as Unicode text
tell application "System Events" to delete file f

Hi adam

sorry for the confusion , i’ll try to go into abit more detail.
a customer sends files to us which land in folder A these items want moving to folder B but sometimes there may be a folder in B with the same name causing an error. so i just want to move the files that don’t have the same name. once they have been moved from A to B then they can be deleted from A but NOT the ones that have the same names , cause someone is going to look in both folders on A and B to check the contents for updated versions.

Is this any clearer.
i know its probably very simple, and i’m just missing some minor detail.
My script may be a bit confusing due to me recreating it across folders on my desktop.
i don’t want to role it out on to the live folders on the drives until i know it works okay.

Thanks for any help or advice you can give

cheers

This works for me Pidge1, from one volume on my hard disk to another (the same as to another machine):

I tested it by placing folderA on the desktop of my machine, folderB on the other. I put file_1, file_2 (just saved blanks) in folderA, and moved file_1 to folderB by hand. Running the script adds file_2 to folderB and deletes it from folderA. but leaves file_1 alone. I think that’s what you want.

Btw, why not compare modification dates to see if they’re the same?


set Bfolder to alias "VolB:folderB:"
set Afolder to alias "VolA:Users:myShortName:Desktop:folderA:"
tell application "Finder"
	set Afiles to files of Afolder
	set Bfiles to name of files of Bfolder as Unicode text
	repeat with someF in Afiles
		if ((name of someF) as Unicode text) is in Bfiles then
		else
			move someF as alias to Bfolder
			delete someF
		end if
	end repeat
end tell

Thanks Adam
will have a go with this and get back to you!!

cheers

Hi Adam

I have modified you script slightly ( hopefully not ruined it! ).
It manages to start moving the folders and but errors after the first one when deleting.
I know i said files/folders in my original post but it will be just folders!
Here is my script which i have now pretty much your script with a few of my variables.

Thanks again for you help.

tell application "Finder"
	set |masstransit in| to alias "folder somewhere on drive"
	set |received gratts| to alias "folder somewhere on drive" 
	tell application "Finder"
		set Afiles to folders of |masstransit in|
		set Bfiles to (name of folders of alias |received gratts| as Unicode text)
		repeat with someF in Afiles
			if ((name of someF) as Unicode text) is in Bfiles then
			else
				move someF as alias to alias |received gratts|
				delete someF
			end if
		end repeat
	end tell
end tell

I don’t know why. This works for me:


set F to choose folder -- this is an alias
set g to choose folder -- this is an alias
set FF to {F, g} -- a list of aliases

tell application "Finder"
repeat with afolder in FF
	delete afolder
end repeat
end tell

Hi Adam

Sorry for being a pain!!
I do think i know what the problem is, once the folders have been moved from A to B then there is the same named folders in both folders A and B then when
the delete part of the script kicks in, it errors after just the first folder is deleted from A.

Am i missing something totally simple.!!!

cheers

Hi jacques

Fantastic!! thats bang on!
Does exactly what i want,
Thank you! It seems once again i was going round the houses abit to get what i wanted.
It was a fairly simple solution in the end but i don’t think i would have got it for a few months anyhow…
Big Big thanks to you to Adam!! you have helped me in the past and i think you have too jacques.
Thank you Both.
Just out of interest
I threw some big files through this script and it took longer than a minute to copy but it still did the delete bit.
is this cause i’m testing it across my desktop and not the actual drives?

cheers

Yes. Once you try this across a busy network, the file transfer time will be an order of magnitude slower. Disk transfers are much faster than 100base-T on a relatively new machine, even when the LAN isn’t very busy. You’re using the Finder to do it, and as someone has already pointed out, there are faster ways.

Go go Command Line :smiley:

Hi Adam

It’s going to be transfering from one Raid array to another, with maximum folders size of no more than 100mb i guess so speed isn’t that important.
Would be interested to see someone recreate this using the command line if they wanna have a go!

thanks for you help

cheers