• 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: How to determine if a folder exists on a system?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to determine if a folder exists on a system?


  • Subject: Re: How to determine if a folder exists on a system?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Wed, 8 Jul 2009 12:59:52 -0400

On Wed, Jul 8, 2009 at 12:38 PM, OSullivan,
Steven<email@hidden> wrote:
> Hello all,
>
> I am trying to do something that I know is very simple (and documented
> somewhere, if I could just FIND it!) and would appreciate any and all
> suggestions as how to go about it.
>
> In pseudocode, I am trying to accomplish:
>
> if folder "/usr/local/bin" does not exist then
>     create it
> else
>     exit block
> end if

One way is to exploit the fact that alias coercion fails if the file
doesn't exist:

set posixPath to "/usr/local/bin"
try
   POSIX file posixPath as alias
on error msg number errNum
   if errNum is -1700 then
       do shell script "mkdir -p " & quoted form of posixPath
   end if
end

If you have a more traditional Mac filespec, you would use just "file"
or "folder" in place of "POSIX file"; you could then use System Events
or the Finder instead of "do shell script" to do the folder creation.

--
Mark J. Reed <email@hidden>
 _______________________________________________
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

  • Follow-Ups:
    • Re: How to determine if a folder exists on a system?
      • From: Emmanuel LEVY <email@hidden>
References: 
 >How to determine if a folder exists on a system? (From: "OSullivan, Steven" <email@hidden>)

  • Prev by Date: Re: Retrieving a "Range" in Excel for storage in a Database
  • Next by Date: Re: How to determine if a folder exists on a system?
  • Previous by thread: How to determine if a folder exists on a system?
  • Next by thread: Re: How to determine if a folder exists on a system?
  • Index(es):
    • Date
    • Thread