2026年03月29日 09:25:36 来源:重庆微芯智软科技有限责任公司 >> 进入该公司展台 阅读量:5
void __fastcall CrnFindFile(String strDir, String strFileExt, TStrings *pList)
{
WIN32_FIND_DATA wfd;
String strFileName;
if (strDir.LastDelimiter("/") != strDir.Length())
strDir += "/";
HANDLE hFind = ::FindFirstFile((strDir + "*.*").c_str(), &wfd);
if (INVALID_HANDLE_VALUE != hFind)
{
do
{
strFileName = String(wfd.cFileName);
if (strFileName == "." || strFileName == "..")
continue;
// 如果是子目录就进入子目录搜索
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
CrnFindFile(strDir + strFileName + "/", strFileExt, pList);
// 将指定扩展名的文件名加入到列表中
if (ExtractFileExt(strFileName).UpperCase() == strFileExt)
pList->Add(strDir + strFileName);
} while(::FindNextFile(hFind, &wfd));
}
::FindClose(hFind);
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CrnFindFile("D://ccrun/", ".MP4", Memo1->Lines);
}