|
// SrchDir.cpp : implementation of the CSrchDir class
//
#include "stdafx.h"
#include "SrchDir.h"
#include "DirMng.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSrchDir
IMPLEMENT_DYNCREATE(CSrchDir, CObject)
/////////////////////////////////////////////////////////////////////////////
// CSrchDir construction/destruction
CSrchDir::CSrchDir()
{
// TODO: add construction code here
}
CSrchDir::~CSrchDir()
{
m_arrayFiles.RemoveAll();
}
/////////////////////////////////////////////////////////////////////////////
// CSrchDir diagnostics
#ifdef _DEBUG
void CSrchDir::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
void CSrchDir::Initialize(const char* pszFiles, void* pParam)
{
m_arrayFiles.RemoveAll();
if (pszFiles)
{
char szFiles[_MAX_PATH];
lstrcpy(szFiles, pszFiles);
for(char* token = strtok(szFiles, " ;*");
token != NULL;
token = strtok( NULL, " ;*"))
{
m_arrayFiles.Add(token);
}
}
}
void CSrchDir::ChkDir(const char* pszPath)
{
if (pszPath == NULL || *pszPath == '\0')
return;
char szNewPath[MAX_PATH];
lstrcpy(szNewPath, pszPath);
if (*(strrchr(szNewPath, '\\') + 1) != '\0')
strcat(szNewPath, "\\"); // C:\;
ChkDirForMultiExt(szNewPath);
}
void CSrchDir::ChkDirForMultiExt(const char* pszPath)
{
WIN32_FIND_DATA fData;
char szNewPath[MAX_PATH];
strcpy(szNewPath, pszPath);
strcat(szNewPath, "*.*");
HANDLE h = ::FindFirstFile(szNewPath, &fData);
if (h != (HANDLE) 0xFFFFFFFF)
{
do
{
if ((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
if (IsValidFile(fData))
{
strcpy(szNewPath, pszPath);
strcat(szNewPath, fData.cFileName);
ChkFile(szNewPath, fData);
}
}
} while (::FindNextFile(h, &fData));
::FindClose(h);
}
}
BOOL CSrchDir::IsValidFile(WIN32_FIND_DATA& fData)
{
const char* p = strrchr(fData.cFileName, '.');
if (p == NULL) return FALSE;
for (int i = 0; i < m_arrayFiles.GetSize(); i++)
{
if (lstrcmpi(m_arrayFiles[i], p) == 0)
return TRUE;
}
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CDirCounter
int CDirCounter::GetFilesInDir(const char* pszStartPath, const char* pszFiles)
{
m_uiFiles = 0;
Initialize(pszFiles, NULL);
ChkDir(pszStartPath);
return m_uiFiles;
}
void CDirCounter::ChkFile(const char* pszPath, WIN32_FIND_DATA& fData)
{
m_uiFiles++;
}
/////////////////////////////////////////////////////////////////////////////
// CDirInfo
void CDirInfo::GetDirInfo(const char* pszStartPath, const char* pszFiles, void* pPara)
{
m_pInfo = (FILE_INFO*) pPara;
Initialize(pszFiles, NULL);
ChkDir(pszStartPath);
}
void CDirInfo::ChkFile(const char* pszPath, WIN32_FIND_DATA& fData)
{
m_pInfo->strFileName = pszPath;
m_pInfo++;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.