typedef CList
<
long
,
long
>
LongList;
typedef CList < CString,CString &> StringList;
int GetFileList(CString path,CString ext,LongList & sizelist,StringList & namelist)
{
CString FileName;
WIN32_FIND_DATA fdata = { 0 };
BOOL bFinished = FALSE;
int nIndex = 0 ;
FileName = path + " *. " + ext;
HANDLE hSearch = FindFirstFile(FileName.GetBuffer( 0 ), & fdata);
if (hSearch == INVALID_HANDLE_VALUE)
return 0 ;
while ( ! bFinished)
{
if ( ! (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
if (nIndex == 0 )
{
sizelist.AddHead(( long )fdata.nFileSizeLow);
FileName.Format( " %s%s " ,path,fdata.cFileName);
namelist.AddHead(FileName);
}
else
{
POSITION pos;
pos = sizelist.FindIndex(nIndex);
sizelist.InsertAfter(pos,( long )fdata.nFileSizeLow);
pos = namelist.FindIndex(nIndex);
FileName.Format( " %s%s " ,path,fdata.cFileName);
namelist.InsertAfter(pos,FileName);
}
nIndex ++ ;
}
if ( ! FindNextFile(hSearch, & fdata))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
bFinished = TRUE;
}
}
FindClose(hSearch);
return nIndex;
}
typedef CList < CString,CString &> StringList;
int GetFileList(CString path,CString ext,LongList & sizelist,StringList & namelist)
{
CString FileName;
WIN32_FIND_DATA fdata = { 0 };
BOOL bFinished = FALSE;
int nIndex = 0 ;
FileName = path + " *. " + ext;
HANDLE hSearch = FindFirstFile(FileName.GetBuffer( 0 ), & fdata);
if (hSearch == INVALID_HANDLE_VALUE)
return 0 ;
while ( ! bFinished)
{
if ( ! (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
if (nIndex == 0 )
{
sizelist.AddHead(( long )fdata.nFileSizeLow);
FileName.Format( " %s%s " ,path,fdata.cFileName);
namelist.AddHead(FileName);
}
else
{
POSITION pos;
pos = sizelist.FindIndex(nIndex);
sizelist.InsertAfter(pos,( long )fdata.nFileSizeLow);
pos = namelist.FindIndex(nIndex);
FileName.Format( " %s%s " ,path,fdata.cFileName);
namelist.InsertAfter(pos,FileName);
}
nIndex ++ ;
}
if ( ! FindNextFile(hSearch, & fdata))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
bFinished = TRUE;
}
}
FindClose(hSearch);
return nIndex;
}
取Long型CList列表中的最大值的索引:
int
GetMaxFileIndex(LongList
&
sizelist,
int
nCount)
{
int nIndex = 0 ;
long nValMax = sizelist.GetHead();
for ( int i = 1 ;i < nCount;i ++ )
{
long nVal = sizelist.GetAt(sizelist.FindIndex(i));
if (nVal > nValMax){
nValMax = nVal;
nIndex = i;
}
}
return nIndex;
}
{
int nIndex = 0 ;
long nValMax = sizelist.GetHead();
for ( int i = 1 ;i < nCount;i ++ )
{
long nVal = sizelist.GetAt(sizelist.FindIndex(i));
if (nVal > nValMax){
nValMax = nVal;
nIndex = i;
}
}
return nIndex;
}