⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmdirscanner.cpp

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*****************************************************************************/
/*                              SOURCE FILE                                  */
/*****************************************************************************/
/*
       $Archive:   $

      $Revision:   $
          $Date:   $
        $Author:   $

    Description:   Contains the implementation of the VMDirScanner class

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
static char OBJECT_ID[] = "$Revision: 2 $ : $Date: 6/17/98 6:32p $";
/*****************************************************************************/


#include "../../../stdafx.h"
#include <assert.h>
#include "VMLastSystemErrorCode.h"
#include "VMDirScanner.h"



/*****************************************************************************/
/*
     FUNCTION NAME:  VMDirScanner::VMDirScanner

       DESCRIPTION:  ctor

             INPUT:  pchRoot - the root of the search
                     pchMask - the file mask for 'filtering' the list
                     bRecurse - TRUE if should recurse, FALSE otherwise
            OUTPUT:  none

           RETURNS:  none
*/
VMDirScanner::VMDirScanner( const char* pchRoot, const char* pchMask, bool bRecurse )
: VMSysLastError()
{
  assert( NULL != pchRoot );
  assert( NULL != pchMask );
  strcpy( m_achMask, pchMask );
  strcpy( m_achCurSearchDir, pchRoot );

  GetCurrentDirectory( MAX_PATH, m_achCurrentDir );
  SetCurrentDirectory( pchRoot );

  m_oFilesIter = m_oFilesFound.begin();
  m_oDirsIter  = m_oDirsFound.begin();

  m_bRecurse  = bRecurse;
  m_bFirstSet = FALSE;

  if ( !m_bRecurse )
  {
    CurDirFileScan();
  }
  else
  {
    m_oDirsFound.push_back( pchRoot );
    ScanForAllFiles( 0 );
  }
  SetCurrentDirectory( m_achCurrentDir );
}
/* End of function "VMDirScanner::VMDirScanner"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  VMDirScanner::~VMDirScanner

       DESCRIPTION:  dtor. cleans out entries in the list

             INPUT:  void
            OUTPUT:  none

           RETURNS:  none
*/
VMDirScanner::~VMDirScanner( void )
{
  m_oFilesFound.clear();
  m_oDirsFound.clear();
}
/* End of function "VMDirScanner::~VMDirScanner"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  VMDirScanner::FindFile

       DESCRIPTION:  looks for the given file in the find set

             INPUT:  pchFileToFind - pointer to the name of the file to find
            OUTPUT:  none

           RETURNS:  true if found, false if not
*/
bool VMDirScanner::FindFile( const char* pchFileToFind )
{
  VM_FILE_FIND_ITER oIter;
 
  for ( oIter  = m_oFilesFound.begin();
        oIter != m_oFilesFound.end();
        oIter++ )
  {
    if ( 0 == strcmp( (*oIter).c_str(), pchFileToFind ) )
    {
      return( true );
    }
  }
  return( false );
}
/* End of function "VMDirScanner::FindFile"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  VMDirScanner::GetFirstFile

       DESCRIPTION:  returns the first string in the found file list (if it
                     exists) 

             INPUT:  void 
            OUTPUT:  none

           RETURNS:  CFastString that is the first entry in the list 
*/
VMString VMDirScanner::GetFirstFile( void )
{
  VMString  oReturn = _T("");

  if ( m_oFilesFound.size() > 0 )
  {
    m_bFirstSet  = TRUE;
    m_oFilesIter = m_oFilesFound.begin();
    oReturn      = (*m_oFilesIter).c_str();
  }
  return( oReturn );
}
/* End of function "VMDirScanner::GetFirstFile"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  VMDirScanner::GetNextFile

       DESCRIPTION:  Gets the next entry in the list, or the first one if
                     the iterator was not initialized

             INPUT:  void
            OUTPUT:  none

           RETURNS:  CString 
*/
VMString VMDirScanner::GetNextFile( void )
{
  VMString  oReturn = _T("");

  if ( m_oFilesFound.size() > 0 )
  {
    if ( !m_bFirstSet )
    {
      m_bFirstSet  = TRUE;
      m_oFilesIter = m_oFilesFound.begin();
      oReturn      = (*m_oFilesIter).c_str();
    }
    else
    {
      m_oFilesIter++;
      if ( m_oFilesIter != m_oFilesFound.end() )
      {
        oReturn = (*m_oFilesIter).c_str();
      }
    }
  }
  return( oReturn );
}
/* End of function "VMDirScanner::GetNextFile"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  VMDirScanner::GetLastDirectory

       DESCRIPTION:  returns the first string in the found file list (if it
                     exists) 

             INPUT:  void 
            OUTPUT:  none

           RETURNS:  CFastString that is the first entry in the list 
*/
VMString VMDirScanner::GetLastDirectory( void )
{
  VMString  oReturn = _T("");

  if (  0 < m_oDirsFound.size() )
  {
    m_oDirsIter = m_oDirsFound.begin();
    if ( m_oDirsIter != m_oDirsFound.end() )
    {  
      m_bFirstSet = true;
      oReturn = (*m_oDirsIter).c_str();
    }
  }
  return( oReturn );
}
/* End of function "VMDirScanner::GetLastDirectory"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  VMDirScanner::GetPrevDirectory

       DESCRIPTION:  Gets the next entry in the list, or the first one if
                     the iterator was not initialized

             INPUT:  void
            OUTPUT:  none

           RETURNS:  CFastString 
*/
VMString VMDirScanner::GetPrevDirectory( void )
{
  VMString  oReturn = _T("");

  if ( m_oDirsFound.size() > 0 )
  {
    if ( !m_bFirstSet )
    {
      m_bFirstSet = TRUE;
      m_oDirsIter = m_oDirsFound.begin();
      oReturn     = (*m_oDirsIter).c_str();
    }
    else
    {
      m_oDirsIter++;
      if ( m_oDirsIter != m_oDirsFound.end() )
      {
        oReturn = (*m_oDirsIter).c_str();
      }
    }
  }
  return( oReturn );
}
/* End of function "VMDirScanner::GetPrevDirectory"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:	VMDirScanner::CurDirFileScan

       DESCRIPTION:	scans a single directory for the files contained in it.
                    does not recurse

             INPUT: void
            OUTPUT:	none
           RETURNS:	FALSE if any errors occurred
*/
bool VMDirScanner::CurDirFileScan( void ) 
{
  char            achCurrentDir[MAX_PATH+1];
  char            achFullPath[MAX_PATH+1];
  WIN32_FIND_DATA xFileInfo;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -