Finder - make new folder solution

From: Roderick Scott Corporation (scott@RSCORP.AB.CA)
Date: Wed May 23 2001 - 15:56:20 AEST


Hello & thanks to all that replied!

I have a working solution which I have attached. It bypasses the
problem I encountered with placing folders within the Desktop Folder
on any other drive except the startup disk. I've tried a couple of
variations but none seem to work around the problem.

I hope this helps [someone else],

Scott

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

-- script to ensure a path is valid.
-- Returns the final path to the calling function (important if
folders are on desktop)
on sureFolder(strPath)

   -- save & modify the text item delimeter to ":" for path manipulation
   set oldSpaceChar to AppleScript's text item delimiters
   set AppleScript's text item delimiters to ":"

   -- direct commands to the Finder
   tell application "Finder"

     activate

     -- test to see if the entire path is valid
     if folder strPath exists then
       -- restore the text item delimeter
       set AppleScript's text item delimiters to oldSpaceChar

       return strPath

     else -- proceed to building the path

       -- initialize a variable to hold the root directory initially,
then the parent after that...
       set strParentFolder to (text item 1 of strPath as string) & ":"

       --  loop through the path, verifying the existence of each level
       -- Note:We don't want the last field after the final : as it
will always be empty and hence the count -1 limit
       -- also, the first item is the root directory/volume name so we
don't start there.
       repeat with i from 2 to ((count (text items in strPath)) - 1)

         -- get the name of the folder
         set strFolderName to (text item i of strPath) as string

         -- extract the sub-path from left to right, adding the final path colon
         set strFolderPath to strParentFolder & strFolderName & ":"

         -- verify existence of this sub-path and build it if it does not exist
         if not (folder strFolderPath exists) then

           -- do the deed, make the folder within the last valid folder
           make new folder at folder strParentFolder with properties
{name:strFolderName}
           set strParentFolder to result as string

         else

           -- update the root path for the next folder if necessary
           set strParentFolder to strFolderPath

         end if


       end repeat
     end if

   end tell

   -- re-activate the script application
   activate

   -- restore the text item delimeter
   set AppleScript's text item delimiters to oldSpaceChar

   return strFolderPath

end sureFolder

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

________________________________________
Scott Sandeman-Allen
Roderick Scott Corporation
Edmonton, Alberta. Canada

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



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