Automatic Folder Creation

I am trying to create a Script that will create a series of folders and Subfolders. So far here is what I have based on another post in this forum. Thanks by the way to the poster of the original script. I am now however trying to add some Subfolders to the PDF folder and I can’t seem to figure this out from other posts. Any help would be appreciated.

set jobNum to text returned of (display dialog “Enter a job number:” default answer “”)
set jobName to text returned of (display dialog “Enter a job name:” default answer “”)
set folderpath to (choose folder with prompt “Select client folder”)
set newJobFolder to my newFold(jobNum, jobName, folderpath)
on newFold(theNumber, theName, thefolder)
set subNameList to {“ClientOriginals”, “LineArtUsed”, “InterWorking”, “ImagesUsed”, “iCut”, “Fonts”, “OutputFinals”}
set itemCount to count of subNameList
tell application “Finder”
set newJobFolder to (make new folder at thefolder with properties ¬
{name:theNumber & " - " & theName})
repeat with i from 1 to itemCount
set thisFolder to make new folder at newJobFolder with properties ¬
{name:“” & item i of subNameList}
if item i of subNameList contains “ClientOriginals” then
make new folder at thisFolder with properties ¬
{name:“TC Production PDF”}
make new folder at thisFolder with properties ¬
{name:“Vendor”}
make new folder at thisFolder with properties ¬
{name:“Working Files”}
make new folder at thisFolder with properties ¬
{name:“Zip Files”}
else if item i of subNameList contains “OutputFinals” then
make new folder at thisFolder with properties ¬
{name:“CFO”}
make new folder at thisFolder with properties ¬
{name:“Finals”}
make new folder at thisFolder with properties ¬
{name:“PDF”}
make new folder at thisFolder with properties ¬
{name:“SplitPDF”}

		end if
		
	end repeat
end tell

end newFold

Thanks in advance.

Hi,

for such a complex folder structure the shell command mkdir is easier to use


set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to POSIX path of (choose folder with prompt "Select client folder")

set folderStructure to "/{ClientOriginals/{'TC Production PDF',Vendor,'Working Files','ZIP Files'},LineArtUsed,InterWorking,ImagesUsed,iCut,Fonts,OutputFinals/{CFO,Finals,PDF/{Folder1,Folder2},SplitPDF}}"
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & quoted form of (jobNum & " - " & jobName) & folderStructure


If you really want to stay with the old fashioned structure you may read that :

version 1 :


set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
(*
set jobNum to "2"
set jobName to "job_Name"
set folderpath to ((path to desktop as text)&"client1:") as alias
*)
set newJobFolder to my newFold(jobNum, jobName, folderpath)
on newFold(theNumber, theName, thefolder)
	set subNameList to {"ClientOriginals", "LineArtUsed", "InterWorking", "ImagesUsed", "iCut", "Fonts", "OutputFinals"}
	set itemCount to count of subNameList
	tell application "Finder"
		set newJobFolder to (make new folder at thefolder with properties ¬
			{name:theNumber & " - " & theName})
		repeat with i from 1 to itemCount
			set thisFolder to make new folder at newJobFolder with properties ¬
				{name:"" & item i of subNameList}
			if item i of subNameList contains "ClientOriginals" then
				make new folder at thisFolder with properties ¬
					{name:"TC Production PDF"}
				make new folder at thisFolder with properties ¬
					{name:"Vendor"}
				make new folder at thisFolder with properties ¬
					{name:"Working Files"}
				make new folder at thisFolder with properties ¬
					{name:"Zip Files"}
			else if item i of subNameList contains "OutputFinals" then
				make new folder at thisFolder with properties ¬
					{name:"CFO"}
				make new folder at thisFolder with properties ¬
					{name:"Finals"}
				set PDFfolder to make new folder at thisFolder with properties ¬
					{name:"PDF"}
				make new folder at PDFfolder with properties {name:"Bachibouzouk"}
				make new folder at thisFolder with properties ¬
					{name:"SplitPDF"}
				
			end if
			
		end repeat
	end tell
end newFold

As I dislike to speak to the Finder, here is
Version 2 which triggers System Events :


set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
(*
set jobNum to "2"
set jobName to "job_Name"
set folderpath to ((path to desktop as text)&"client1:") as alias
*)
set newJobFolder to my newFold(jobNum, jobName, folderpath)
on newFold(theNumber, theName, thefolder)
	set subNameList to {"ClientOriginals", "LineArtUsed", "InterWorking", "ImagesUsed", "iCut", "Fonts", "OutputFinals"}
	set itemCount to count of subNameList
	set thefolder to thefolder as text
	tell application "System Events"
		set newJobFolder to path of (make new folder at folder thefolder with properties ¬
			{name:theNumber & " - " & theName})
		repeat with i from 1 to itemCount
			set thisFolder to path of (make new folder at folder newJobFolder with properties ¬
				{name:item i of subNameList as text})
			if item i of subNameList contains "ClientOriginals" then
				tell folder thisFolder
					make new folder at it with properties ¬
						{name:"TC Production PDF"}
					make new folder at it with properties ¬
						{name:"Vendor"}
					make new folder at it with properties ¬
						{name:"Working Files"}
					make new folder at it with properties ¬
						{name:"Zip Files"}
				end tell
			else if item i of subNameList contains "OutputFinals" then
				tell folder thisFolder
					make new folder at it with properties ¬
						{name:"CFO"}
					make new folder at it with properties ¬
						{name:"Finals"}
					set PDFfolder to path of (make new folder at it with properties ¬
						{name:"PDF"})
					make new folder at it with properties ¬
						{name:"SplitPDF"}
				end tell
				make new folder at folder PDFfolder with properties {name:"Bachibouzouk"} # moved here to take care of the tell folder thisFolder block
				
			end if
			
		end repeat
		
	end tell
end newFold

KOENIG Yvan (VALLAURIS, France) vendredi 13 septembre 2013 18:45:15

Thanks for the quick Reply, both methods work perfectly.

Richard.:slight_smile: