首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> Delphi

Delphi 檔案管理器進階功能:檔案搜尋、磁碟資訊與類型過濾

     編輯:Delphi

Function 選單三大功能

  • Search:搜尋檔案並顯示屬性
  • Disk View:顯示磁碟總/可用空間
  • View Type:設定檔案顯示過濾器

檔案搜尋實作

初嘗試 FileSearch 但回傳值異常,改用 FindFirst/FindNext 標準流程:

procedure TFMForm.Search1Click(Sender: TObject);
var SearchForm: TSearchForm; FileAttrForm: TFileAttrForm;
    FindIt, Path: String; SearchRec: TSearchRec; Return: Integer;
begin
  SearchForm := TSearchForm.Create(Self);
  with SearchForm do
  begin
    SearchFile.Text := ''; SearchPath.Text := DirectoryOutline.Directory;
    if (ShowModal <> idCancel) and (SearchFile.Text <> '') and (SearchPath.Text <> '') then
    begin
      FindIt := SearchPath.Text + '\' + SearchFile.Text;
      Return := FindFirst(FindIt, faAnyFile, SearchRec);
      if Return <> 0 then FindIt := ''
      else FindIt := ExpandFileName(SearchRec.Name);
    end;
    if FindIt = '' then
      MessageDlg('Cannot find the file in current directory.', mtWarning, [mbOk], 0)
    else
    begin
      Path := ExtractFilePath(FindIt);
      FindIt := ExtractFileName(FindIt);
      FileAttrForm := TFileAttrForm.Create(Self);
      ShowFileAttr(FileAttrForm, FindIt, Path);
    end;
  end;
end;

磁碟資訊顯示

TDiskViewForm 對話框,DriveEdit.OnChange 事件即時查詢:

procedure TDiskViewForm.DriveEditChange(Sender: TObject);
var Free, Total: LongInt;
begin
  Free := DiskFree(0);  // 0 = 當前磁碟機
  Total := DiskSize(0);
  FreeSpace.Text := IntToStr(Free) + ' bytes.';
  TotalSpace.Text := IntToStr(Total) + ' bytes.';
end;

三編輯框 ReadOnly = True 僅供顯示。參數可改為使用者指定磁碟機字母。

檔案類型過濾

見上一節 ViewType1Click 實作。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved