• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating nested folders
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating nested folders


  • Subject: Re: Creating nested folders
  • From: Stan Cleveland via AppleScript-Users <email@hidden>
  • Date: Sat, 14 Aug 2021 13:21:42 -0700

On August 14, 2021 at 2:00:43 AM, Jan Erik Moström via AppleScript-Users
(email@hidden) wrote:
I have the structure 
        /a/b 
and need to create a file in folder 
        /a/b/c/d/e 

So I would like to call a function that makes sure that the hierarchy 
"/a/b/c/d/e" exists (which it sometimes might do)? 
Jan, below is my go-to handler that gives a degree of control over folder
creation, including the creation of missing intermediate folders.

Stan C.

set targetPosix to "/a/b/c/d/e"
set {creatingIntermediates, settingPermissions, suppressingErrors} to {true, 
false, false}
set {dirCreated, errText} to directoryCreate(targetPosix, 
creatingIntermediates, settingPermissions, suppressingErrors)

on directoryCreate(targetPosix, creatingIntermediates, settingPermissions,
suppressingErrors)
        set targetPosix to quoted form of targetPosix
        set pParam to "" -- default
        if creatingIntermediates then set pParam to "-p "
        try
                if settingPermissions then
                        do shell script "mkdir -m 'a=rwx' " & pParam &
targetPosix
                else
                        do shell script "mkdir " & pParam & targetPosix
                end if
                set dirCreated to true
        on error errText number errNum
                if errText contains "File exists" then
                        set dirCreated to true
                else
                        set dirCreated to false
                        if not suppressingErrors then error errText number
errNum
                end if
        end try
        if dirCreated then set errText to ""
        return {dirCreated, errText}
end directoryCreate

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Creating nested folders (From: Jan Erik Moström via AppleScript-Users <email@hidden>)

  • Prev by Date: Creating nested folders
  • Next by Date: Reading and writing Finder preferences
  • Previous by thread: Creating nested folders
  • Next by thread: Reading and writing Finder preferences
  • Index(es):
    • Date
    • Thread