Re: Tell Finder Make New Folder wierdness!

From: Walter Ian Kaye (osas@NATURAL-INNOVATIONS.COM)
Date: Wed May 23 2001 - 17:08:57 AEST


Here's a solution, with some small enhancements:

on sureFolder(strPath)
   if (offset of ":" in strPath) is 0 then return false --not a path
   if strPath ends with ":" then
      set isFolderPath to true
      set strFile to ""
      if strPath is not ":" then set strPath to text 1 thru -2 of strPath
      set pathList to PathToList(strPath)
      set strPath to strPath & ":"
   else
      set isFolderPath to false
      set pathList to PathToList(strPath)
      set strFile to item -1 of pathList
      set pathList to items 1 thru -2 of pathList
      set strPath to ListToPath(pathList)
   end if

   tell application "Finder"

      if folder strPath exists then

         return true

      else -- proceed to building the path

         set theDisk to item 1 of pathList
         if not (exists alias (theDisk & ":")) then
            error "No such volume. (" & theDisk & ")" number -35
         end if

         repeat with i from 2 to (count pathList)

            set strParentPath to my ListToPath(items 1 through (i - 1) of pathList)
            set strFolderPath to my ListToPath(items 1 through i of pathList)
            set strFolderName to item i of pathList

            if not (exists alias strFolderPath) then
               make new folder at alias strParentPath with properties {name:strFolderName}
            end if

         end repeat

      end if

   end tell

   return strFile

end sureFolder


on PathToList(strPath)
   set oldDelims to AppleScript's text item delimiters
   set AppleScript's text item delimiters to ":"
   try
      set pathList to every text item of strPath
   on error
      set pathList to {}
      set AppleScript's text item delimiters to oldDelims
   end try
   set AppleScript's text item delimiters to oldDelims
   pathList
end PathToList

on ListToPath(pathList)
   set oldDelims to AppleScript's text item delimiters
   set AppleScript's text item delimiters to ":"
   try
      set strPath to pathList as string
   on error
      set strPath to ""
      set AppleScript's text item delimiters to oldDelims
   end try
   set AppleScript's text item delimiters to oldDelims
   strPath & ":"
end ListToPath

------------------------------



This archive was generated by hypermail 2b29 : Sun May 27 2001 - 12:00:29 AEST