How to copy a file so it creates missing folders in the path

Richard Gaskin ambassador at fourthworld.com
Fri May 10 14:01:00 EDT 2013


Klaus' raw materials are helpful, but I'm lazy and this comes up a lot 
for me so I wrote a function to take care of it for any number of levels 
in the path - from the old stdLib project:

--
-- stdEnsurePath
--
-- Checks the path specified in pPath to make sure each of its
-- directories exists, creating any that need to be as it goes.
--
on stdEnsurePath pPath
   set the itemdel to "/"
   --
   put item 1 of pPath into tTestPath
   put pPath into tDestFolders
   delete item 1 of tDestFolders
   repeat for each item tFolder in tDestFolders
     put "/"&tFolder after tTestPath
     if there is not a folder tTestPath then
       create folder tTestPath
       Err the result, "Couldn't create folder "&quote&tTestPath&quote
     end if
   end repeat
end stdEnsurePath


--
-- ERR
--
-- Simple method for checking and reporting errors to the user.
-- Most useful to call for those circumstances where you would
-- check the result and display it if it contains an error.
-- By default, it exits to top, but you can pass any value
-- in the optional third param to prevent this exit.
--
on Err pResultStr, pErrMessage, pNoExitFlag
   if pResultStr is not empty then
     if pErrMessage is empty then answer pResultStr
     else  answer pErrMessage
     if "appProgress" is in the windows then
       close stack "appProgress"
     end if
     if pNoExitflag is empty then exit to top
   end if
end Err


--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  Follow me on Twitter:  http://twitter.com/FourthWorldSys





More information about the use-livecode mailing list