/* sdirpath.cc

   directory class with methods to create and delete
   directory trees

   Author: Martin Kay

   Started: 05/26/2010
   Last Updated: 11/01/2010

   Changes:
      11/01/2010 - Added method Exists() - M.Kay

*/


class sdirpath
   function makeDirTree
     parameters cDirTree
     // By: www.autotraker.com
     // This function will build an entire directory tree
     // just pass the entire tree and it will build it.
     // returns true if the directory exists if it has build it.
     // cDirTree = "c:\temp2\temp2\temp3\temp4\temp5\temp6"
     // makeDirTree(cDirTree)
     // can use either imageHlp.dll or dbgHelp.dll
     // (in the system32 directory). Since some versions of
     // imageHlp.dll may not support this function, we are
     // putting it in a try, catch
     local cDir
     cDir = iif(right(cDirTree,1)=="\",cDirTree,cDirTree+"\")
     if type("MakeSureDirectoryPathExists")<>"FP"
        try
           extern cLogical MakeSureDirectoryPathExists(cString);
              "IMAGEHLP.DLL"
        catch(exception e)
        endtry
      endif

      if type("MakeSureDirectoryPathExists")<>"FP"
         extern cLogical MakeSureDirectoryPathExists(cString);
          "dbgHelp.dll"
      endif

      return MakeSureDirectoryPathExists(cDir)



//   function removedirtree
//      parameters cDirTree
//
//      local cpath
//
//      cpath = cDirtree



   //////////////////////////////////////////
   // Method:  Exists()
   //
   // Purpose: Returns True if directory path exists
   //          otherwise, returns False
   //
   // Parameter:  cDir - folder path to test for existence
   function exists( cDir )

   local lExists

   if empty( cDir )
      return false
   endif

   lExists = true

   try
      cd (cDir)

   catch (exception e)
      //? e.code
      //? e.message
      if e.code = 0 or e.code = 210 or e.code = 211 or e.code = 409 or e.code = 405
         //   0 = unknown error
         // 210 = invalid directory
         // 211 = invalid drive
         // 409 = directory does not exist
         // 405 = path too long
         lExists = false
      endif

      // other possible exception - access denied
   endtry

   return lExists

         

endclass