您的位置:首页 > 其它

VC-获取文件夹中的指定类型的所有文件名和文件大小

2010-05-01 16:03 826 查看
米度软件:www.midosoft.cn

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;

米度软件:www.midosoft.cn
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: