bool Platform::dumpDirectories( const char *path, Vector<StringTableEntry> &directoryVector, S32 depth, bool noBasePath )
{
   bool retVal = recurseDumpDirectories( path, "", directoryVector, -1, depth, noBasePath );

   clearExcludedDirectories();

   return retVal;
}
static bool recurseDumpDirectories(const char *basePath, const char *subPath, Vector<StringTableEntry> &directoryVector, S32 currentDepth, S32 recurseDepth, bool noBasePath)
{
   TempAlloc< char > search( 1024 );

   //-----------------------------------------------------------------------------
   // Compose our search string - Format : ([path]/[subpath]/*)
   //-----------------------------------------------------------------------------

   char trail = basePath[ dStrlen(basePath) - 1 ];
   char subTrail = subPath ? subPath[ dStrlen(subPath) - 1 ] : '\0';

   if( trail == '/' )
   {
      // we have a sub path and it's not an empty string
      if(  subPath  && ( dStrncmp( subPath, "", 1 ) != 0 ) )
      {
         if( subTrail == '/' )
            dSprintf(search, search.size, "%s%s*", basePath,subPath );
         else
            dSprintf(search, search.size, "%s%s/*", basePath,subPath );
      }
      else
         dSprintf( search, search.size, "%s*", basePath );
   }
   else
   {
      if(  subPath  && ( dStrncmp( subPath, "", 1 ) != 0 ) )
         if( subTrail == '/' )
            dSprintf(search, search.size, "%s%s*", basePath,subPath );
         else
            dSprintf(search, search.size, "%s%s/*", basePath,subPath );
      else
         dSprintf(search, search.size, "%s/*", basePath );
   }

#ifdef UNICODE
   TempAlloc< WCHAR > searchStr( dStrlen( search ) + 1 );
   convertUTF8toUTF16( search, searchStr, searchStr.size );
#else
   char* searchStr = search;
#endif

   backslash( searchStr );

   //-----------------------------------------------------------------------------
   // See if we get any hits
   //-----------------------------------------------------------------------------

   WIN32_FIND_DATA findData;
   HANDLE handle = FindFirstFile(searchStr, &findData);
   if (handle == INVALID_HANDLE_VALUE)
      return false;

   //-----------------------------------------------------------------------------
   // add path to our return list ( provided it is valid )
   //-----------------------------------------------------------------------------
   if( !Platform::isExcludedDirectory( subPath ) )
   {

      if( noBasePath )
      {
         // We have a path and it's not an empty string or an excluded directory
         if( ( subPath  && ( dStrncmp( subPath, "", 1 ) != 0 ) ) )
            directoryVector.push_back( StringTable->insert( subPath ) );
      }
      else
      {
         if( ( subPath  && ( dStrncmp( subPath, "", 1 ) != 0 ) ) )
         {
            char szPath [ 1024 ];
            dMemset( szPath, 0, 1024 );
            if( trail != '/' )
               dSprintf( szPath, 1024, "%s%s", basePath, subPath );
            else
               dSprintf( szPath, 1024, "%s%s", basePath, &subPath[1] );
            directoryVector.push_back( StringTable->insert( szPath ) );
         }
         else
            directoryVector.push_back( StringTable->insert( basePath ) );
      }
   }

   //-----------------------------------------------------------------------------
   // Iterate through and grab valid directories
   //-----------------------------------------------------------------------------

#ifdef UNICODE
   TempAlloc< char > fileName( 1024 );
#endif

   do
   {
      if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      {
         // skip . and .. directories
         if (dStrcmp(findData.cFileName, TEXT( "." )) == 0 || dStrcmp(findData.cFileName, TEXT( ".." )) == 0)
            continue;

#ifdef UNICODE
         convertUTF16toUTF8( findData.cFileName, fileName, fileName.size );
#else
         char* fileName = findData.cFileName;
#endif

         // skip excluded directories
         if( Platform::isExcludedDirectory( fileName ) )
            continue;

         if( ( subPath  && ( dStrncmp( subPath, "", 1 ) != 0 ) ))
         {
            if( subTrail == '/' )
               dSprintf(search, search.size, "%s%s", subPath, fileName);
            else
               dSprintf(search, search.size, "%s/%s", subPath, fileName);
            char* child = search;

            if( currentDepth < recurseDepth || recurseDepth == -1 )
               recurseDumpDirectories(basePath, child, directoryVector, currentDepth+1, recurseDepth, noBasePath );

         }
         else
         {
            char* child;
            if( trail == '/' )
               child = fileName;
            else
            {
               dSprintf(search, search.size, "/%s", fileName);
               child = search;
            }

            if( currentDepth < recurseDepth || recurseDepth == -1 )
               recurseDumpDirectories(basePath, child, directoryVector, currentDepth+1, recurseDepth, noBasePath );
         }
      }      
   }
   while(FindNextFile(handle, &findData));

   FindClose(handle);
   return true;
}
 static bool recurseDumpDirectories(const char *basePath, const char *subPath, Vector<StringTableEntry> &directoryVector, S32 currentDepth, S32 recurseDepth, bool noBasePath)
 {
   char Path[1024];
   DIR *dip;
   struct dirent *d;

   if (subPath && (dStrncmp(subPath, "", 1) != 0))
     {
       if ((basePath[dStrlen(basePath) - 1]) == '/')
 	dSprintf(Path, 1024, "%s%s", basePath, subPath);
       else
 	dSprintf(Path, 1024, "%s/%s", basePath, subPath);
     }
   else
     dSprintf(Path, 1024, "%s", basePath);
   dip = opendir(Path);
   if (dip == NULL)
     return false;
   //////////////////////////////////////////////////////////////////////////
   // add path to our return list ( provided it is valid )
   //////////////////////////////////////////////////////////////////////////
   if (!Platform::isExcludedDirectory(subPath))
     {
       if (noBasePath)
 	{
 	  // We have a path and it's not an empty string or an excluded directory
 	  if ( (subPath && (dStrncmp (subPath, "", 1) != 0)) )
 	    directoryVector.push_back(StringTable->insert(subPath));
 	}
       else
 	{
 	  if ( (subPath && (dStrncmp(subPath, "", 1) != 0)) )
 	    {
 	      char szPath[1024];
 	      dMemset(szPath, 0, 1024);
 	      if ( (basePath[dStrlen(basePath) - 1]) != '/')
 		dSprintf(szPath, 1024, "%s%s", basePath, subPath);
 	      else
 		dSprintf(szPath, 1024, "%s%s", basePath, &subPath[1]);
 	      directoryVector.push_back(StringTable->insert(szPath));
 	    }
 	  else
 	    directoryVector.push_back(StringTable->insert(basePath));
 	}
     }
   //////////////////////////////////////////////////////////////////////////
   // Iterate through and grab valid directories
   //////////////////////////////////////////////////////////////////////////

	while (d = readdir(dip))
	{
		bool	isDir;
		isDir = false;
		if (d->d_type == DT_UNKNOWN)
		{
			char child [1024];
			if ((Path[dStrlen(Path) - 1] == '/'))
				dSprintf(child, 1024, "%s%s", Path, d->d_name);
			else
				dSprintf(child, 1024, "%s/%s", Path, d->d_name);
			isDir = Platform::isDirectory (child);
		}
		else if (d->d_type & DT_DIR)
		isDir = true;

       if ( isDir )
 	{
 	  if (dStrcmp(d->d_name, ".") == 0 ||
 	      dStrcmp(d->d_name, "..") == 0)
 	    continue;
 	  if (Platform::isExcludedDirectory(d->d_name))
 	    continue;
 	  if ( (subPath && (dStrncmp(subPath, "", 1) != 0)) )
 	    {
 	      char child[1024];
 	      if ((subPath[dStrlen(subPath) - 1] == '/'))
 		dSprintf(child, 1024, "%s%s", subPath, d->d_name);
 	      else
 		dSprintf(child, 1024, "%s/%s", subPath, d->d_name);
 	      if (currentDepth < recurseDepth || recurseDepth == -1 )
 		recurseDumpDirectories(basePath, child, directoryVector,
 				       currentDepth + 1, recurseDepth,
 				       noBasePath);
 	    }
 	  else
 	    {
 	      char child[1024];
 	      if ( (basePath[dStrlen(basePath) - 1]) == '/')
 		dStrcpy (child, d->d_name);
 	      else
 		dSprintf(child, 1024, "/%s", d->d_name);
 	      if (currentDepth < recurseDepth || recurseDepth == -1)
 		recurseDumpDirectories(basePath, child, directoryVector,
 				       currentDepth + 1, recurseDepth,
 				       noBasePath);
 	    }
 	}
     }
   closedir(dip);
   return true;
 }