📄 findfiles.pas
字号:
unit FindFileS;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SkinCtrls, StdCtrls, SkinBoxCtrls, DynamicSkinForm,
ComCtrls, Shellapi, FileCtrl, Menus, SkinMenus, Mask;
type
TFindFileForm = class(TForm)
spDynamicSkinForm1: TspDynamicSkinForm;
StatusBar: TspSkinLabel;
ViewMenu1: TspSkinPopupMenu;
N16: TMenuItem;
N17: TMenuItem;
N18: TMenuItem;
N19: TMenuItem;
Panel1: TspSkinPanel;
spSkinStdLabel3: TspSkinStdLabel;
FileEdit: TspSkinEdit;
spSkinStdLabel1: TspSkinStdLabel;
Edit1: TspSkinEdit;
Button2: TspSkinButton;
RadioBox1: TspSkinCheckRadioBox;
RadioBox2: TspSkinCheckRadioBox;
FindButton: TspSkinButton;
StopButton: TspSkinButton;
spSkinPanel1: TspSkinPanel;
FoundFiles: TspSkinListView;
bsSkinScrollBar7: TspSkinScrollBar;
spSkinScrollBar6: TspSkinScrollBar;
procedure FoundFilesDblClick(Sender: TObject);
procedure FoundFilesColumnClick(Sender: TObject; Column: TListColumn);
procedure FoundFilesCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
procedure Button2Click(Sender: TObject);
procedure N16Click(Sender: TObject);
procedure N17Click(Sender: TObject);
procedure N18Click(Sender: TObject);
procedure N19Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Folders: Integer;
StartTime: DWord;
SortedColumn: Integer;
Descending: Boolean;
end;
var
FindFileForm: TFindFileForm;
implementation
uses
Main;
{$R *.dfm}
procedure TFindFileForm.FoundFilesDblClick(Sender: TObject);
begin
if FoundFiles.Selected <> nil then
with FoundFiles.Selected do
ShellExecute(0, 'Open', PChar(Caption), nil, PChar(SubItems[0]), SW_NORMAL);
end;
procedure TFindFileForm.FoundFilesColumnClick(Sender: TObject;
Column: TListColumn);
begin
TListView(Sender).SortType := stNone;
if Column.Index <> SortedColumn then
begin
SortedColumn := Column.Index;
Descending := False;
end
else
Descending := not Descending;
TListView(Sender).SortType := stText;
end;
procedure TFindFileForm.FoundFilesCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
begin
if SortedColumn = 0 then
Compare := CompareText(Item1.Caption, Item2.Caption)
else if SortedColumn > 0 then
Compare := CompareText(Item1.SubItems[SortedColumn-1],
Item2.SubItems[SortedColumn-1]);
if Descending then Compare := -Compare;
end;
procedure TFindFileForm.Button2Click(Sender: TObject);
var
strCaption, strDirectory: string;
wstrRoot: WideString;
begin
strCaption := '请选择查找路径:';
wstrRoot := '';
SelectDirectory(strCaption, wstrRoot, strDirectory);
if Strdirectory <> '' then begin
Edit1.Text := strDirectory;
end;
end;
procedure TFindFileForm.N16Click(Sender: TObject);
begin
if FoundFiles.Selected <> nil then
with FoundFiles.Selected do
ShellExecute(0, 'Open', PChar(Caption), nil, PChar(SubItems[0]), SW_NORMAL);
end;
procedure TFindFileForm.N17Click(Sender: TObject);
var
FileTemp: string;
begin
try
if FoundFiles.Selected = nil then Exit;
with FoundFiles.Selected do begin
if copy(Caption, Length(Caption), 1) <> '\' then
FileTemp := SubItems[0] + '\' + Caption
else FileTemp := SubItems[0] + Caption;
end;
FilesetAttr(FileTemp, 0);
DeleteFile(FileTemp);
if not FileExists(FileTemp) then begin
StatusBar.Caption := '删除文件: "' + FileTemp + '" 成功!';
FoundFiles.Selected.Delete;
end
else StatusBar.Caption := '删除文件: "' + FileTemp + '" 失败!';
except
end;
end;
procedure TFindFileForm.N18Click(Sender: TObject);
var
FileTemp: string;
I: integer;
begin
try
if Application.MessageBox('你确认要删除搜索到的所有文件吗?', '警告', mb_yesno + mb_iconquestion + mb_topmost) <> IDYES then Exit;
for i := 0 to FoundFiles.Items.Count - 1 do begin
with FoundFiles.Items[i] do begin
if copy(Caption, Length(Caption), 1) <> '\' then
FileTemp := SubItems[0] + '\' + Caption
else FileTemp := SubItems[0] + Caption;
end;
FilesetAttr(FileTemp, 0);
DeleteFile(FileTemp);
if not FileExists(FileTemp) then
StatusBar.Caption := '删除文件: "' + FileTemp + '" 成功!'
else StatusBar.Caption := '删除文件: "' + FileTemp + '" 失败!';
end;
FoundFiles.Clear;
except
end;
end;
procedure TFindFileForm.N19Click(Sender: TObject);
begin
FoundFiles.Clear;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -