This finds all files matching the supplied criteria and starting from the supplied root directory. The relative paths [to the root] of the files found will populate the supplied vector (arg 1) This function uses recursion to read all the directories implied by the criteria. The criteria is split by the forward slash and each part is examined in turn. Those parts occuring before the last forward slash are called directory parts and the part occuring after the last forward slash is the file part. If the criteria begins with a forward slash the root directory (from which the process starts) is set to the filesystem root (/). The criteria is then advanced one place before being split. If the criteria begins with a ../ sequence we take note of the current directory and step back one place. If there are multiple ../ sequences we step back multiple times. The ./ sequence is ignored. If the criteria begins with any other sequence this is assumed to be a part that will be applied to the contents of the current directory. If bLimit is true then the search for files will be limited to files matching the last part in the directories starting from the root and matching all the previous parts. But if false the files found will include the above but if the last part also matches to directories these will be examined as well. False is the default so beware!

Return TypeFunction nameArguments
hzEcode_scanfiles(hzArray<hzString>&,const char*,bool,)

Declared and defined in file: hzDirectory.cpp

Function Logic:

0:START 1:i 2:unknown 3:Return E_OK 4:unknown 5:items items 6:items rootVal 7:unknown 8:* 9:curr items 10:unknown 11:unknown 12:Return E_NOTFOUND 13:items 14:unknown 15:rootVal rootVal 16:unknown 17:i 18:crit items rootDir 19:Return _scanfiles_r(files,parts,rootDir,0,bLimit)

Function body:

hzEcode _scanfiles (hzArray<hzString>& files)const char* criteria, bool bLimit, 
{
   //  Category: Directory
   //  
   //  This finds all files matching the supplied criteria and starting from the supplied root directory. The relative
   //  paths [to the root] of the files found will populate the supplied vector (arg 1)
   //  
   //  Arguments: 1) files  The vector of files found
   //     2) criteria The scaning criteria
   //     3) bLimit  Boolean limit
   //  
   //  Returns: E_ARGUMENT If the pathsofar is empty or no parts are specified
   //     E_OPENFAIL If the directory cannot be opened
   //     E_CORRUPT If a directory entry cannot be stated
   //     E_OK  If the directory is successfully scanned
   //  
   //  This function uses recursion to read all the directories implied by the criteria. The criteria is split by the forward slash
   //  and each part is examined in turn. Those parts occuring before the last forward slash are called directory parts and the part
   //  occuring after the last forward slash is the file part.
   //  
   //  If the criteria begins with a forward slash the root directory (from which the process starts) is set to the filesystem root
   //  (/). The criteria is then advanced one place before being split.
   //  
   //  If the criteria begins with a ../ sequence we take note of the current directory and step back one place. If there are multiple
   //  ../ sequences we step back multiple times. The ./ sequence is ignored.
   //  
   //  If the criteria begins with any other sequence this is assumed to be a part that will be applied to the contents of the current
   //  directory.
   //  
   //  If bLimit is true then the search for files will be limited to files matching the last part in the directories starting from
   //  the root and matching all the previous parts. But if false the files found will include the above but if the last part also
   //  matches to directories these will be examined as well. False is the default so beware!
   hzArray<hzString>   parts ;     //  Parts of full path
   hzChain         rootVal ;       //  For building the path so far
   const char*     i ;             //  Pathname iterator
   hzString        rootDir ;       //  The path so far
   hzString        cwd ;           //  Current working dir
   hzString        root ;          //  Root (rebuilt directory path)
   hzString        curr ;          //  Current working directory excluding leading slash
   hzString        crit ;          //  Basename criteria
   uint32_t        nLevel ;        //  Directory step backs (../)
   uint32_t        nCount ;        //  Step back iterator
   i = criteria ;
   if (!i || !i[0])
       return E_OK ;
   if (i[0]== CHAR_FWSLASH)
   {
       //  Start at the root directory
       rootVal.AddByte(CHAR_FWSLASH) ;
       i++ ;
   }
   else
   {
       //  If the criteria starts with a ../ sequence we have to go back from the current directory but if not then we will start at
       //  the current directory
       GetCurrDir(cwd) ;
       rootVal = cwd ;
       if (i[0]== CHAR_PERIOD && i[1]== CHAR_PERIOD && i[2]== CHAR_FWSLASH)
       {
           curr = *cwd + 1;
           SplitStrOnChar(parts, curr, CHAR_FWSLASH) ;
           for (nLevel = parts.Count() - 1; i[0]== CHAR_PERIOD && i[1]== CHAR_PERIOD && i[2]== CHAR_FWSLASH ; nLevel--, i += 3);
           if (nLevel < 0)
               return E_NOTFOUND ;
           root.Clear() ;
           for (nCount = 0; nCount < nLevel ; nCount++)
           {
               rootVal += "/" ;
               rootVal += parts[nCount] ;
           }
       }
       if (i[0]== CHAR_PERIOD && i[1]== CHAR_FWSLASH)
           i += 2;
   }
   crit = i ;
   SplitStrOnChar(parts, crit, CHAR_FWSLASH) ;
   rootDir = rootVal ;
   return _scanfiles_r(files, parts, rootDir, 0,bLimit) ;
}