create subfolders

Hi,

I am trying to make an applescript which has to create a bunch of folders with subfolders. And at this point I am stuck…

e.g. I want to create a folder with name: PDF and within that folder I also want to have subfolders as originals customer, Certified PDF, Reports,…
So, this folder should look like this:

PDF/originals customer
PDF/Certified PDF
PDF/Reports

The script has to be flexible, I want to adjust it later (for instance when I need to create more (sub-)folders.
Can anyone help me out please?

regards,

Kris

Rip21:

Here’s a quick one… Try this out. It only allows you to add folders to the main folder (PDF) but by adding to the property subFolders you can add as many as you need. If you need folders inside folders inside folders you’ll need a recursive routine. Not impossible but this script won’t do it in its current state.


property subFolders : {"Customer Originals", "Certified PDFs", "Reports"} -- Add and delete from this as needed
property mainFolder : "PDF" -- Change this as needed

tell application "Finder"
	activate
	if not (exists folder mainFolder of desktop) then -- Check to see if the folder exists
		set destFolder to make folder at desktop with properties {name:mainFolder} -- If not, make it.
	else
		set destFolder to folder mainFolder of desktop -- If so, set the variable to it.
	end if
	repeat with thisFolder in subFolders -- Repeat as many times as there are variables in the property subFolders (in this case 3). The variable thisFolder is "Customer Originals" in the first loop, then "Certified PDFs" in the next, and so on...
		if not (exists folder (thisFolder as string) of destFolder) then -- Check for the subfolder. If it doesn't exist, make it. Otherwise, ignore and keep going.
			make folder at destFolder with properties {name:thisFolder}
		end if
	end repeat
	open destFolder -- Open the folder
	set current view of window 1 to list view --  I just prefer this view so I added it in. This, for whatever reason, doesn't always work but I like it when it does!
end tell

Hope this helps.

Cheers,
Jim Neumann
BLUEFROG

Hi Jim,

thanks for your proposal, but unfortunately that’s not what I was thinking of… my fault, I think I provided you with not enough info.
Here’s more…
I wrote this script (and it is working) but for every folder this script generates (pictures, fonts, originals customer,…) I also want subfolders. E.g. in the folder Originals Customer, I’d like subfolders like images, documents, links. In the folder single files I’d like to create subfolders like tuckbox, flyer, blister, leaflet and within these subfolders also new subfolders.
The structure should look like this:

rootfolder/Originals Customer/images
rootfolder/Originals Customer/links
rootfolder/Originals Customer/documents
rootfolder/single files/tuckbox
rootfolder/single files/flyer
rootfolder/single files/leaflet
rootfolder/single files/blister

Do you know if this is easy scriptable?

regards,

Kris

Here’s the current script:

tell application "Finder"
	--try
	--make new folder in (folder "FileServer:Incoming Files") with properties {name:project}
	--on error
	--Display dialog "Project already exists on the server."
	--end try
	try
		make new folder in (folder "Retail") with properties {name:order}
	end try
	
	try
		make new folder in (folder ("Retail:" & order)) with properties {name:"Pictures"}
		make new folder in (folder ("Retail:" & order)) with properties {name:"Fonts"}
		make new folder in (folder ("Retail:" & order)) with properties {name:"Originals Customer"}
		make new folder in (folder ("Retail:" & order)) with properties {name:"Outputfiles"}
		make new folder in (folder ("Retail:" & order)) with properties {name:"singlefiles"}
		make new folder in (folder ("Retail:" & order)) with properties {name:"S&R"}
		
	end try
	--display dialog "Error writing to file : " & errMsg
	--on error errMsg
	--	display dialog "Project already exists: " & errMsg
	--tell application "Finder"
	--	open folder ("FileServer:Production Files:" & shortname & ":" & project)
	--end tell
	--tell application "Finder"
	--	activate
	--	end tell
end tell

tell application "Finder"
	set root_folder to make new folder at desktop with properties {name:"rootfolder"}
	set root_folder2 to make new folder at root_folder with properties {name:"Originals Customer"}
	
	make new folder at root_folder2 with properties {name:"links"}
	make new folder at root_folder2 with properties {name:"Images"}
	make new folder at root_folder2 with properties {name:"documents"}
	
	set root_folder3 to make new folder at root_folder with properties {name:"single files"}
	
	make new folder at root_folder3 with properties {name:"tuckbox"}
	make new folder at root_folder3 with properties {name:"flyer"}
	make new folder at root_folder3 with properties {name:"leaflet"}
	make new folder at root_folder3 with properties {name:"blister"}
	
end tell

I think it will help you.

Rajeev

If the Master folder will be the same, you could just create it manually, then add to it with this approach:


--Initiate a list of the subfolders you create
property AddedSubFolders : {}

--Create a new folder and it is added to the subfolder list
set theFolder to (choose folder with prompt "Create New Folder; Click 'Choose' to add to Folder List") as string
set AddedSubFolders to AddedSubFolders & theFolder

--This is optional if you want to access any created subfolder directly
set openThisFolder to (choose from list AddedSubFolders with prompt "Open A Folder" default items item 1 of AddedSubFolders) as string
try--Deals with error message if you cancel this dialog
	tell application "Finder" to open folder openThisFolder as string
end try