Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Duplicate Folder Names

I wish to duplicate a group of folders, including their names, but not their contents. In other words, a group of empty folders with the same names, located within another specified folder. How would one create an Applescript to accomplish that?

PowerBook G4 Mac OS X (10.4)

Posted on Apr 22, 2006 10:58 AM

Reply
4 replies

Apr 22, 2006 11:41 AM in response to Ralphjh

Try this:

tell application "Finder"
set sourceFolder to (choose folder with prompt "Choose the folder to copy")
set destFolder to (choose folder with prompt "Choose the destination")
if sourceFolder ≠ destFolder then
repeat with eachFolder in (get folders of sourceFolder as alias list)
set FolderName to ((name of folder eachFolder) as text)
make new folder at destFolder with properties {name:FolderName}
end repeat
end if
end tell


The script asks for two folders - source and destination. As long as they're different it gets a list of the folders in source, then creates a corresponding list of folders in dest.

It's not recursive - so it'll only work for the top level folders. If you need it to be recursive it's not a big change - post back if you need help.

Apr 22, 2006 12:23 PM in response to Camelot

Hi Camelot, thanks for the response.

I assume that by "top level folders" you mean source and destination folders at the same level and not at "root" level.

(My understanding of "recursive" is "successive iterations in solving a math problem." I'm not exactly sure what you mean by recursive in this instance.)

Apr 22, 2006 12:41 PM in response to Ralphjh

I assume that by "top level folders" you mean source and destination folders at the same level and not at "root" level.


No, I mean that if the source folder looks like:

Top Folder
--Subfolder 1
----Sub-subfolder 1
----Sub-subfolder 2
--Subfolder 2


then the script, as written, would create a 'Subfolder 1' and a 'Subfolder 2' in the destination folder. The folders within those folders (e.g. 'Sub-subfolder 1' and 'Sub-subfolder 2' would not be created in the destination folder). That's what I mean by the 'top folder' only.

If you want to recreate the entire hierarchy then you need to make the script recursive - that way, for each folder in the source folder it looks inside that for any subfolders that also need to be created. Since you don't know in advance how deep the folder structure could be a recursive script that just keeps on going is the best solution. Let me know if you need to go an arbitrary number of folders down, or whether just copying the top-level hierarchy is sufficient.

Duplicate Folder Names

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.