Create a directory along with intermediate directories

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Create a directory along with intermediate directories

Post by daryl » Mon Jun 10, 2013 7:11 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Create a directory along with intermediate directories

Post by FourthWorld » Mon Jun 10, 2013 7:17 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

daryl
Posts: 47
Joined: Mon Apr 29, 2013 11:43 pm

Re: Create a directory along with intermediate directories

Post by daryl » Mon Jun 10, 2013 7:40 pm

Thanks FourthWorld, Much appreciated.

Regards,

Daryl

Post Reply