Newby help... Easy folder script

Hi,

I’m sure this is something easily done, but i’m just a newby and not up to speed yet.

I’m after a script to duplicate a predetermined folders contents to another folder but not to copying the folder enclosed files, just the folder name, so they are essentially empty folders. It will also need to replace duplicates.

Can anyone help me

Thanks
Adam:)

Hi Thomas

You seem to contridict yourself a little in your question!
So bare with me if i get this wrong.
I assume you have a folder with several other folders inside, and what you want to do is copy these internal folders into
another folder, but not whats inside them!!! so essentially your just copying the names of the folders:
try this:


tell application "Finder"
	set p to folders of (choose folder) as alias list --pick a folder here
	set t to (choose folder) --> choose where the folders will go here
	repeat with n in p
		set f to name of n
		make new folder in t with properties {name:f}
	end repeat
end tell

theres no overwriting in this script i can’t see the point if the folders you are creating are empty,
however i’m still a little bit unsure what you want. so see how you get on with the above script

Good Luck

Hi pidge1,

Sorry, i wrote that kinda badly. But essentially you have it correct! All it needs is a replace if it finds a duplicate. You see, the first folders contents could change over time, and i want the second copyied folder to have every folder that was ever inside the first. So the script will add new folders, and just replace if it’s the same. Does this make sense?

Thanks

Okay found this replacing statement but it won’t work. any ideas?

tell application “Finder”
set p to folders of (choose folder) as alias list --pick a folder here
set t to (choose folder) → choose where the folders will go here
repeat with n in p
set f to name of n
make new folder in t with properties {name:f} with replacing
end repeat
end tell

Thanks

Hi Thomas

Your right the replacing bit doesn’t work.
i don’t think it works with folders just files.
what you need is a recursive script that goes into sub folders.
i think the tricky bit here is creating them at the other end if you like still in the same hierachy.
i’ll have a look but there’s guys on here that are better at this type of stuff than me.
so i’m sure someone else may throw there cap in on this one.

Hi Thomas

this terminal unixy command would maybe be another option for you.

rsync -r --include="*/" --exclude="*"  folders to copy from here    folder to go to here

just tested it and it copied folders and sub folders no files, it remembers whats been
synced as well so the second time you run it it will only update the new folders.

not sure how familiar you are with the terminal but this is pretty easy.
copy the rysnc----> “*” and paste into terminal then drag the folder you want copying onto the terminal then do the same with the destination folder then hit return.

Not sure if this is a solution but i think an applescript would be quite complicated.

Hi Pidge1

Not all that familiar with the terminal, but gave it a go. I think i followed your messge right…this is what i typed in the terminal:

rsync -r --include=“/“/Users/thomas/Desktop/A/ --exclude=””/Users/thomas/Desktop/B/

A whole bunch on text came rolling thru the terminal window, but nothing else happened. Folder A has 2 test folders and a file, and B is still empty.

I must be doing it wrong?

Thanks

Here is the error message:

rsync error: syntax or usage error (code 1) at /SourceCache/rsync/rsync-24.1/rsync/main.c(1143)

I’m running 10.4.9 and appear to be running rsync 2.6.3. Maybe i need an update?

Thanks

Hi Thomas

You need both the include and the exclude bit before your folder paths.

rsync -r --include=“/" --exclude="” path to folder A path to folder B

Hi again,

i must be stupid or something. I can’t get it to work

This is what i typed into terminal:

rsync -r --include=“/" --exclude="”/Users/thomas/Desktop/A/ /Users/thomas/Desktop/B/

and i get the error:

rsync error: syntax or usage error (code 1) at /SourceCache/rsync/rsync-24/rsync/main.c(906)

Hi Thomas

Are you running an intel machine.
if so this might be the problem.
I’m not sure if it is exactly what you want anyhow.
i’ll try and have a look at the applescript route. in the meantime why don’t you “google” rsync
and see if the syntax has changed.

Hi Thomas

I must apologise up front regarding this script it is very crude.
But test it and see how it works for you and let me know if were going in the right direction.

tell application "Finder"
	set e to every item of (choose folder)
	set n to (choose folder)
	duplicate e to n with replacing
	set f to files of entire contents of n as alias list
	repeat with i in f
		delete i
	end repeat
end tell

Hi,

Thanks for working so much on this for me.

The last script may be crude, and that’s fine becuase it appears to work!
It does give an applescript error “Can’t make every file of <> of alias “HD:Users:thomas:Desktop:B:” into type <>”

will keep trying, this is a good start. Thanks.

I swear we just had a thread about this a month ago or so ::runs off to search:: :smiley:

Found it! - http://bbs.applescript.net/viewtopic.php?id=20170

Hi thomas did it work once before it thru up this error you mentioned?
or did it not work at all?

Excellent!! Thanks to both pidge1 and James. This work perfectly. 10 points.

You got that exactly right, except there needs to be a space between --exclude=“*” and the source path.

Model: Mac Pro
AppleScript: 2.2.1
Browser: Firefox 3.0.3
Operating System: Mac OS X (10.5)