filefind.cpp

来自「一个国人自己实现图像库的程序(有参考价值)」· C++ 代码 · 共 53 行

CPP
53
字号
#include "stdafx.h"
#include "..\Include\FileFind.h"

//===================================================================
BOOL  FCFileFind::FindFile (PCTSTR szPathName)
{
	if (m_hFileFind != INVALID_HANDLE_VALUE)
		this->FindClose () ;

	WIN32_FIND_DATA		FileData ;
	m_hFileFind = ::FindFirstFile (szPathName, &FileData) ;
	if (m_hFileFind == INVALID_HANDLE_VALUE)
		return FALSE ;

	TCHAR	szDir[_MAX_DIR] ;
	_splitpath (szPathName, m_szFindPath, szDir, NULL, NULL) ;
	lstrcat (m_szFindPath, szDir) ; // 获得查找路径

	//	目录 "." & ".."
	if (!lstrcmp (TEXT("."), FileData.cFileName) || !lstrcmp (TEXT(".."), FileData.cFileName))
		return this->FindNext () ;	// Skip . and ..

	m_dwFileAttribute = FileData.dwFileAttributes ;
	m_dwFileSize = (m_dwFileAttribute == FILE_ATTRIBUTE_DIRECTORY) ? -1 : FileData.nFileSizeLow ;
	lstrcpy (m_szFullName, m_szFindPath) ;
	lstrcat (m_szFullName, FileData.cFileName) ;
	return TRUE ;
}
//===================================================================
BOOL  FCFileFind::FindNext ( )
{
	if (m_hFileFind == INVALID_HANDLE_VALUE)
		return FALSE ;

	WIN32_FIND_DATA		FileData ;
	if (::FindNextFile (m_hFileFind, &FileData) == 0)
	{
		this->FindClose () ;
		return FALSE ;
	}

	//	目录 "." & ".."
	if (!lstrcmp (TEXT("."), FileData.cFileName) || !lstrcmp (TEXT(".."), FileData.cFileName))
		return this->FindNext () ;	// Skip . and ..

	m_dwFileAttribute = FileData.dwFileAttributes ;
	m_dwFileSize = (m_dwFileAttribute == FILE_ATTRIBUTE_DIRECTORY) ? -1 : FileData.nFileSizeLow ;
	lstrcpy (m_szFullName, m_szFindPath) ;
	lstrcat (m_szFullName, FileData.cFileName) ;
	return TRUE ;
}
//===================================================================

⌨️ 快捷键说明

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