Sunday, October 17, 2021

#1 2005-07-20 05:19:50 am

easyrider
Member
Registered: 2005-07-20
Posts: 3

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.

smile

Offline

 

#2 2005-07-20 07:48:23 am

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Creating Folders with Subfolders

Try this:

Applescript:

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.


Filed under: Finder

Offline

 

#3 2005-07-20 09:05:46 am

easyrider
Member
Registered: 2005-07-20
Posts: 3

Re: Creating Folders with Subfolders

Cheers Guardian 34!!!

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

Offline

 

#4 2005-07-20 12:14:27 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Creating Folders with Subfolders

This will do it:

Applescript:

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


Filed under: Finder

Offline

 

#5 2005-07-21 02:28:41 am

easyrider
Member
Registered: 2005-07-20
Posts: 3

Re: Creating Folders with Subfolders

perfect.

cheers.

Offline

 

#6 2005-08-16 04:36:51 pm

mrlowry
Member
Registered: 2005-08-16
Posts: 2

Re: Creating Folders with Subfolders

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

Offline

 

#7 2005-08-16 07:42:18 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Creating Folders with Subfolders

Try something like this:

Applescript:

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.

Offline

 

#8 2005-08-16 11:42:43 pm

mrlowry
Member
Registered: 2005-08-16
Posts: 2

Re: Creating Folders with Subfolders

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!

Offline

 

#9 2021-09-16 05:07:27 pm

bocciaman
Member
From:: YouTube
Registered: 2019-07-22
Posts: 13
Website

Re: Creating Folders with Subfolders

Thank you, @Bruce for this script!


Filed under: , folder, applescript, create

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)