Tell Finder Make New Folder wierdness!

From: Roderick Scott Corporation (scott@RSCORP.AB.CA)
Date: Wed May 23 2001 - 08:21:53 AEST


I hope someone can help me. I'm trying to write a handler that will
crawl a folder path and verify the existence of the path, making new
folders as necessary to fulfill the path. Unfortunately, once my
script passes the point of creating a folder, it can no longer use
that new folder to place anything into it i.e. another folder. I
simply get an error that the last folder I created does not exist -
and therefore I cannot make a new folder in it.

Here is my code so far. Note I return a True, but have not finished
adding any error trapping:

>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 true
>
>    else -- proceede to building the path
>      -- initialize a variable to hold the
>      set strFolderPath to ""
>
>      -- 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
>      repeat with i from 1 to ((count (text items in strPath)) - 1)
>
>        -- extract the sub-path from left to right, adding the final
>path colon
>        set strFolderPath to ((text items 1 through i of strPath) as
>string) & ":"
>
>        -- get the name of the folder
>        set strFolderName to text item i of strPath
>
>        -- 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 strParentFolder with properties
>{name:strFolderName}
>
>        end if
>
>        -- capture the last folder to place next folder into
>        set strParentFolder to strFolderPath as alias
>
>      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 true
>
>end sureFolder

Thanks in advance for any assistance,

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

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

End of MACSCRPT Digest - 21 May 2001 to 22 May 2001 (#2001-164)
***************************************************************



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