1. 지정한 폴더에 있는 파일들만 몽땅 가져오기... 날짜, 파일명
폴더는 제 작업에 필요없어서 제외... 혹 할려면 폴더를 StringList에 넣고 재귀호출 그
냥 재귀호출 해도 되는데.. 정렬문제 때문에 저번에그렇게 한 것 같습니다. 원하는데로 되었음..
2. FileName으로 정렬, Date로 정렬
3. 파일명 binary 검색... 정확한 파일이 있는지 확인을 위한 것으로...
정확하지 않으면... -1을 Return, 조금 수정하면 근접한 파일도 찾을 수 있을 것입니다.
이것은 몇 년 전에 필요해서 한 것 같은데.. 생각 안남.... ㅋㅋㅋ
끝.... 부산에서 월천 박영목.... 행복하세요..... 바바 ^^
-------------------------------------------------------------------------------------------
typedef struct ST_FILE_DATE
{
FILETIME ftDate;
AnsiString asFile;
} stFileDate;
void __fastcall QSortFileName( TList *sl, int left, int right ) //TStringList *sl, int left, int right )
{
int i, j;
stFileDate *sPx, *sPw;
stFileDate *p, *q;
do
{
p = (stFileDate*)sl->Items[ (left+right)/2 ]; //sPx = sl->Strings[ (left+right)/2 ];
i = left;
j = right;
do
{
//while( strcmp( sl->Strings[i].c_str(), sPx.c_str() ) < 0 ) i++;
while( i<=right ) //while( sl-> p-> ) i++; //while( strcmp( sl->Strings[i].c_str(), sPx.c_str() ) < 0 ) i++; //sl->Strings[i].c_str(), < sPx.c_str()
{
q = (stFileDate*)sl->Items[ i ];
//if( q->ftDate < p->ftDate ) i++;
if( strcmp( q->asFile.c_str(), p->asFile.c_str() ) < 0 ) //sl->Strings[i].c_str(), sPx.c_str() ) < 0 ) //(q->ftDate.dwHighDateTime < p->ftDate.dwHighDateTime) || ((q->ftDate.dwHighDateTime == p->ftDate.dwHighDateTime) && (q->ftDate.dwLowDateTime < p->ftDate.dwLowDateTime)) )
{
i++;
}
else break;
}
//while( strcmp( sl->Strings[j].c_str(), sPx.c_str() ) > 0 ) j--;
while( 0<=j )
{
q = (stFileDate*)sl->Items[ j ];
//if( q->ftDate > p->ftDate ) j--;
if( strcmp( q->asFile.c_str(), p->asFile.c_str() ) > 0 ) //if( (q->ftDate.dwHighDateTime > p->ftDate.dwHighDateTime) || ((q->ftDate.dwHighDateTime == p->ftDate.dwHighDateTime) && (q->ftDate.dwLowDateTime > p->ftDate.dwLowDateTime)) )
{
j--;
}
else break;
}
if( i>j ) break;
sPw = (stFileDate*)sl->Items[ i ];
sl->Items[i] = sl->Items[j];
sl->Items[j] = sPw;
} while( ++i <= --j );
if( j - left < right - i )
{
if( left < j ) QSortFileName( sl, left, j );
left = i; j = right;
}
else
{
if( i < right ) QSortFileName( sl, i, right );
right = j; i = left;
}
}
while( left < right );
}
void __fastcall QSortDate( TList *sl, int left, int right )
{
int i, j;
stFileDate *sPx, *sPw;
stFileDate *p, *q;
do
{
p = (stFileDate*)sl->Items[ (left+right)/2 ]; //sPx = sl->Strings[ (left+right)/2 ];
i = left;
j = right;
do
{
while( i<=right ) //while( sl-> p-> ) i++; //while( strcmp( sl->Strings[i].c_str(), sPx.c_str() ) < 0 ) i++; //sl->Strings[i].c_str(), < sPx.c_str()
{
q = (stFileDate*)sl->Items[ i ];
//if( q->ftDate < p->ftDate ) i++;
if( (q->ftDate.dwHighDateTime < p->ftDate.dwHighDateTime) || ((q->ftDate.dwHighDateTime == p->ftDate.dwHighDateTime) && (q->ftDate.dwLowDateTime < p->ftDate.dwLowDateTime)) )
{
i++;
}
else break;
}
while( 0<=j )
{
q = (stFileDate*)sl->Items[ j ];
//if( q->ftDate > p->ftDate ) j--;
if( (q->ftDate.dwHighDateTime > p->ftDate.dwHighDateTime) || ((q->ftDate.dwHighDateTime == p->ftDate.dwHighDateTime) && (q->ftDate.dwLowDateTime > p->ftDate.dwLowDateTime)) )
{
j--;
}
else break;
}
//while( strcmp( sl->Strings[j].c_str(), sPx.c_str() ) > 0 ) j--; //sl->Strings[j].c_str(), > sPx.c_str()
if( i>j ) break;
sPw = (stFileDate*)sl->Items[ i ];
sl->Items[i] = sl->Items[j];
sl->Items[j] = sPw;
} while( ++i <= --j );
if( j - left < right - i )
{
if( left < j ) QSortDate( sl, left, j );
left = i; j = right;
}
else
{
if( i < right ) QSortDate( sl, i, right );
right = j; i = left;
}
} while( left < right );
}
//------------------------------------------------------------------------------
static int BinarySearch( TList *sl, int max, AnsiString asValue )
{
int pos;
int begin = 0;
int end = max - 1;
int cond = 0;
stFileDate *p;
while(begin <= end)
{
pos = (begin + end) / 2;
p = (stFileDate*)sl->Items[ pos ];
if( (cond = strcmp( p->asFile.c_str(), asValue.c_str()))==0 )
return pos;
else if(cond < 0)
begin = pos + 1;
else
end = pos - 1;
}
return -1;
}
|