FindClose - C++ Builder

C++ Builder 参考手册 ➙ System::Sysutils ➙ FindClose


释放 FindFirst 申请的资源

头文件:#include
命名空间:System::Sysutils
函数原型:

void __fastcall FindClose(TSearchRec &F);

参数:

  • F:函数 FindFirst 返回的 TSearchRec 类型的结构体;

返回值:

  • 无。结束查找,释放 FindFirst 申请的资源。

例子:把 C:\Windows 文件夹里面的内容显示在 TStringGrid 里面

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    StringGrid1->RowCount = 2;
    StringGrid1->Cells[0][0] = L"文件名";
    StringGrid1->Cells[1][0] = L"大小";
    StringGrid1->Cells[2][0] = L"时间";
    StringGrid1->Cells[3][0] = L"属性";

    int iRowNo = 1;
    TSearchRec sr;
    if(FindFirst(L"C:\\Windows\\*.*", faAnyFile, sr) == 0)
    {
        do{
            UnicodeString sAttr;
            sAttr += sr.Attr & faReadOnly ? L"r" : L"-";
            sAttr += sr.Attr & faArchive  ? L"a" : L"-";
            sAttr += sr.Attr & faHidden   ? L"h" : L"-";
            sAttr += sr.Attr & faSysFile  ? L"s" : L"-";
            StringGrid1->RowCount = iRowNo + 1;
            StringGrid1->FixedRows = 1;
            StringGrid1->Cells[0][iRowNo] = sr.Name;
            StringGrid1->Cells[1][iRowNo] = sr.Attr & faDirectory ? String(L"<文件夹>") : IntToStr(sr.Size);
            StringGrid1->Cells[2][iRowNo] = FormatDateTime(L"yyyy/mm/dd hh:nn:ss.zzz",sr.TimeStamp);
            StringGrid1->Cells[3][iRowNo] = sAttr;
            iRowNo++;
        } while(FindNext(sr) == 0);
        FindClose(sr);
    }
}

运行结果

运行结果

相关:

  • System::Sysutils::FindFirst
  • System::Sysutils::FindNext
  • System::Sysutils::FindClose
  • System::Sysutils::TSearchRec
  • System::Sysutils::FileSearch
  • System::Sysutils::FileExists
  • System::Sysutils::DirectoryExists
  • System::Sysutils::FileAge
  • System::Sysutils::FileGetDate
  • System::Sysutils::FileGetDateTimeInfo
  • System::Sysutils::FileSetDate
  • System::Sysutils::FileGetAttr
  • System::Sysutils::FileSetAttr
  • System::Sysutils::FileIsReadOnly
  • System::Sysutils::FileSetReadOnly
  • System::Sysutils::CreateDir
  • System::Sysutils::ForceDirectories
  • System::Sysutils::RemoveDir
  • System::Sysutils::GetCurrentDir
  • System::Sysutils::SetCurrentDir
  • System::Sysutils::DeleteFile
  • System::Sysutils::RenameFile
  • System::Sysutils::IsAssembly
  • System::Sysutils::DiskFree
  • System::Sysutils::DiskSize
  • System::Sysutils::FileDateToDateTime
  • System::Sysutils::DateTimeToFileDate
  • System::Sysutils

C++ Builder 参考手册 ➙ System::Sysutils ➙ FindClose

你可能感兴趣的:(FindClose - C++ Builder)