Creating Folders with Subfolders

Hi.

I don’t know the first thing about creating scripts, and I really need some help. I’m trying to create a script which names the main folder, creates subfolders, and names them aswell (which includes the main folder title) i.e - main folder - ‘xxxx work folder’, with subfolders - ‘xxxx images’, ‘xxxx artwork’, ‘xxxx visuals’ etc. what i want is when i change ‘xxxx’ to a specific job number on the main folder, i.e. ‘3995’, that this number replaces all the ‘xxxx’ in the subfolders.

probably really simple, but i don’t have a clue.

cheers people.

:slight_smile:

Try this:

property newFolderName : "work folder"
property subFolderNames : {"images", "artwork", "visuals"}

repeat
	display dialog "Enter job number:" default answer ""
	set jobNumber to text returned of result
	if result is not "" then exit repeat
end repeat

choose folder with prompt "Create job folder '" & jobNumber & "' in this folder:"
try
	tell application "Finder"
		make new folder at result with properties {name:(jobNumber & " " & newFolderName)}
		set jobFolder to result
		
		repeat with i from 1 to (count subFolderNames)
			make new folder at jobFolder with properties {name:(jobNumber & " " & (item i of subFolderNames))}
		end repeat
	end tell
on error errorMsg number errorNum
	display dialog "Error: (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1
end try

If you want all your main job folders to be put in the same place (instead of having the script ask each time), then you would only need to change a couple lines.

Cheers Guardian 34!!!

One more question - to then create more subfolders within ‘images’ what do i do?

This will do it:

property newFolderName : "work folder"
property mainSubFolderNames : {"images", "artwork", "visuals"}
property imageSubFolderNames : {"a", "b"}

repeat
	display dialog "Enter job number:" default answer ""
	set jobNumber to text returned of result
	if result is not "" then exit repeat
end repeat

choose folder with prompt "Create job folder '" & jobNumber & "' in this folder:"
try
	tell application "Finder"
		make new folder at result with properties {name:(jobNumber & " " & newFolderName)}
		set jobFolder to result as alias
		
		repeat with i from 1 to (count mainSubFolderNames)
			make new folder at jobFolder with properties {name:(jobNumber & " " & (item i of mainSubFolderNames))}
		end repeat
		
		repeat with i from 1 to (count imageSubFolderNames)
			make new folder at ((jobFolder as text) & jobNumber & " images:") as alias with properties {name:(item i of imageSubFolderNames)}
		end repeat
	end tell
on error errorMsg number errorNum
	display dialog "Error: (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1
end try

perfect.

cheers.

What if you wanted the sub-folders to have different sub-sub folders? Let’s say I want folder “images” to have sub folders
“a”, “b”, “c” and folder “artwork” to have sub folders “d”,“e”,“f”? Assuming, of course, that these choices are always static, and so could be pulled from an array.

Thanks!

Mr. Lowry

Try something like this:

property subFolders : {"images/a", "images/b", "images/c", "artwork/d", "artwork/e", "artwork/f", "visuals"}

repeat
	display dialog "Enter job number:" default answer ""
	set jobNumber to text returned of result
	if result is not "" then exit repeat
end repeat

choose folder with prompt "Create job folder '" & jobNumber & "' in this folder:"
set baseFolder to (POSIX path of result) & (jobNumber & " work folder/")

try
	repeat with thisItem in subFolders
		do shell script "mkdir -p " & quoted form of (baseFolder & thisItem)
	end repeat
on error errorMsg number errorNum
	display dialog "Error: (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1
end try

With this, you can add or remove items to the subFolders list to meet your needs.

Thanks Guardian34–that’s great–I didn’t know you could just add subfolders with a “/”.

I’ve put your script into use already.

Cheers!

Thank you, @Bruce for this script!