Making a folder with subfolders...

I can make a folder where I want it. But I cannot seem to then create several subfolders within that folder. It keeps giving me an error when I try to make the subfolders. I have tried dozens and dozens of various ways of writing the command. None of them seem to work. If need be I can post the script that I have.

Thanks

Jmax

Making subfolders is the same as making folders. You just make them somewhere else. :wink: This makes a folder on the desktop and puts two subfolders inside it:

tell application "Finder"
  set theFolder to (make new folder at desktop with properties {name:"My folder"})
  make new folder at theFolder with properties {name:"Subfolder 1"}
  make new folder at theFolder with properties {name:"Subfolder 2"}
end tell

(The word ‘new’ seems to be optional.)

In practice, you’d probably want to check first to ensure that your folder/subfolders didn’t already exist before trying to create them:

set subfolderNames to {"Subfolder 1", "Subfolder 2"}

tell application "Finder"
  if not (folder "My folder" of the desktop exists) then
    set theFolder to make new folder at desktop with properties {name:"My folder"}
  else
    set theFolder to folder "My folder" of the desktop
  end if
  repeat with listItemRef in subfolderNames
    set thisName to contents of listItemRef
    if not (folder thisName of theFolder exists) then
      make new folder at theFolder with properties {name:thisName}
    end if
  end repeat
end tell

Thanks Nigel. This is almost the exact code I was trying and it was not working. Perhaps “almost” is the operative word there. :wink:

Also, I am working in Smile. It seems that I has a couple of odd quirks that I am just now finding out about. I like it way better than the editor that comes from Apple. But I am having to get used to a couple of strange things in how it runs. For instance, you have to put all your handlers at the top in the text window that you write the script in and then move them once it is working to below the on run handler. Oh well, it was free and that is my favorite price.

Thanks again for you help.

Jmax