Page 1 of 1

Create a directory along with intermediate directories

Posted: Mon Jun 10, 2013 7:11 pm
by daryl
Hi Folks,

I need to create a directory where some intermediate directory(ies) may not exist. Does LiveCode have anything equivalent to the unix mkidr -p command, or will I have to check this manually? I figure I can split on slash and then loop through creating directories if they don't exist, but just wanted to check if I am missing something. I have searched through the documentation with out any luck.

Any help would be much appreciated.

Thanks,

Daryl

Re: Create a directory along with intermediate directories

Posted: Mon Jun 10, 2013 7:17 pm
by FourthWorld

Code: Select all

--
-- 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

Re: Create a directory along with intermediate directories

Posted: Mon Jun 10, 2013 7:40 pm
by daryl
Thanks FourthWorld, Much appreciated.

Regards,

Daryl