2008年7月9日 星期三

Search File Sample

/************ using WIN32 API **************/
HANDLE hSearch;
CString path_name;
bool bFinished = false;
WIN32_FIND_DATA find_data;

m_curpath = path_name.Left(path_name.GetLength()-strlen("kghost.exe"));
path_name = m_curpath + "*.txt";
hSearch = FindFirstFile(path_name, &find_data);
if( hSearch==INVALID_HANDLE_VALUE )
return;

while( bFinished==false )
{
CString str = find_data.cFileName;
...
if( !FindNextFile(hSearch, &find_data) )
bFinished = true;
}
FindClose(hSearch);
/****************************************/
其中
WIN32_FIND_DATA
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
} WIN32_FIND_DATA, *PWIN32_FIND_DATA;