Unit_SearchDir.pas 部分unit Unit_SearchDir;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, FileCtrl; procedure FindFile(DirName:string;var FileList:TStrings; IncSubDir:boolean=True);
procedure delay(msec:integer);type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
ListBox1: TListBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure delay(msec:integer);
var
FirstTickCount : real;
begin
FirstTickCount := GetTickCount();
FirstTickCount := FirstTickCount + msec;
While FirstTickCount > GetTickCount() do
Application.HandleMessage;
end;procedure FindFile(DirName:string;var FileList:TStrings; IncSubDir:boolean=True);
var
DS:TSearchRec;
i,p,j:integer;
Path:string;
DirList:TStrings;
F: TFileStream;
buff: array[0..100] of char;
NotNul: boolean;
begin
i := 0;
DirName := ExcludeTrailingPathDelimiter(DirName);
DirList := TStringList.Create;
DirList.Add(DirName);
while i < DirList.Count do
begin
Path := DirList.Strings[i] + '\';
if FindFirst(Path + '*.*', faAnyFile, Ds) = 0 then
repeat
if (Ds.Attr and faDirectory) = 0 then
begin
F:=TFileStream.Create(Path+Ds.Name,fmOpenRead);
F.Position:=0;
F.Read(buff,100);
NotNul:=False;
for j:=0 to 99 do
begin
if (buff[j]<>#00) then
begin
NotNul:=True;
break;
end;
end;
if not NotNul then FileList.Add(Path + Ds.Name);
F.Free;
end
else
if IncSubDir and (Ds.Name[1] <> '.') then DirList.Add(Path + Ds.Name);
until FindNext(Ds) <> 0;
Inc(i);
p := i * 100 div DirList.Count;
if p > Form1.ProgressBar1.Position then
Form1.ProgressBar1.Position := p;
FindClose(Ds);
end; DirList.Free;
end;procedure TForm1.Button1Click(Sender: TObject);
var
FileList:TStrings;
Dir: string;
begin
if SelectDirectory('请选择检测路径','/',Dir)=true then
begin
Listbox1.Items.Clear;
Button1.Enabled:=False;
FileList := TStringList.Create;
ProgressBar1.Position:=0;
FindFile(Dir, FileList, true);
if FileList.Count=0 then Listbox1.Items.Add('NO DUMMY FILES!!!')
else Listbox1.Items.AddStrings(FileList);
FileList.Free;
Button1.Enabled:=true;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, FileCtrl; procedure FindFile(DirName:string;var FileList:TStrings; IncSubDir:boolean=True);
procedure delay(msec:integer);type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
ListBox1: TListBox;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
end;var
Form1: TForm1;implementation{$R *.dfm}procedure delay(msec:integer);
var
FirstTickCount : real;
begin
FirstTickCount := GetTickCount();
FirstTickCount := FirstTickCount + msec;
While FirstTickCount > GetTickCount() do
Application.HandleMessage;
end;procedure FindFile(DirName:string;var FileList:TStrings; IncSubDir:boolean=True);
var
DS:TSearchRec;
i,p,j:integer;
Path:string;
DirList:TStrings;
F: TFileStream;
buff: array[0..100] of char;
NotNul: boolean;
begin
i := 0;
DirName := ExcludeTrailingPathDelimiter(DirName);
DirList := TStringList.Create;
DirList.Add(DirName);
while i < DirList.Count do
begin
Path := DirList.Strings[i] + '\';
if FindFirst(Path + '*.*', faAnyFile, Ds) = 0 then
repeat
if (Ds.Attr and faDirectory) = 0 then
begin
F:=TFileStream.Create(Path+Ds.Name,fmOpenRead);
F.Position:=0;
F.Read(buff,100);
NotNul:=False;
for j:=0 to 99 do
begin
if (buff[j]<>#00) then
begin
NotNul:=True;
break;
end;
end;
if not NotNul then FileList.Add(Path + Ds.Name);
F.Free;
end
else
if IncSubDir and (Ds.Name[1] <> '.') then DirList.Add(Path + Ds.Name);
until FindNext(Ds) <> 0;
Inc(i);
p := i * 100 div DirList.Count;
if p > Form1.ProgressBar1.Position then
Form1.ProgressBar1.Position := p;
FindClose(Ds);
end; DirList.Free;
end;procedure TForm1.Button1Click(Sender: TObject);
var
FileList:TStrings;
Dir: string;
begin
if SelectDirectory('请选择检测路径','/',Dir)=true then
begin
Listbox1.Items.Clear;
Button1.Enabled:=False;
FileList := TStringList.Create;
ProgressBar1.Position:=0;
FindFile(Dir, FileList, true);
if FileList.Count=0 then Listbox1.Items.Add('NO DUMMY FILES!!!')
else Listbox1.Items.AddStrings(FileList);
FileList.Free;
Button1.Enabled:=true;
end;
end;end.
解决方案 »
- 关于cxGrid1TableView1
- 怎么建立视图
- 编写windows服务程序的互斥体问题
- 无法模拟点击网页按钮,前几天还可以...
- 怎么来改变程序中的按钮的样式!比如把常规的方形的改为椭圆的!UP有分
- 高分求:类似“qq好友上线通知”功能
- 哪里能下载到李维的《Delphi 7高效数据库程序设计》全书??
- hint 问题
- 这个功能应该如何实现?高分请教,不够可以再加
- 奇怪,奇怪,真奇怪。按MDI子窗体的关闭按钮为何该子窗体不关闭而是最小化了呢?用CLOSE方法同样是进行了最小化。
- 图像显示中出现白线,请教这是什么原因.
- 各位帮帮忙,indy的IdFtp控件怎样实现断点上传文件的方法,最好有实例代码?谢谢各位了,搞的头都大了!
object Form1: TForm1
Left = 337
Top = 188
BorderIcons = [biSystemMenu]
BorderStyle = bsSingle
Caption = #26816#27979#20809#30424#22403#22334#25991#20214
ClientHeight = 239
ClientWidth = 418
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = #23435#20307
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 12
object Label1: TLabel
Left = 24
Top = 208
Width = 48
Height = 12
Caption = #26816#27979#36827#31243
end
object Button1: TButton
Left = 152
Top = 166
Width = 107
Height = 25
Caption = #26816#27979#22403#22334#25991#20214
TabOrder = 0
OnClick = Button1Click
end
object ProgressBar1: TProgressBar
Left = 80
Top = 205
Width = 305
Height = 16
TabOrder = 1
end
object ListBox1: TListBox
Left = 24
Top = 16
Width = 361
Height = 137
ItemHeight = 12
TabOrder = 2
end
end
program Project1;uses
Forms,
Unit_SearchDir in 'Unit_SearchDir.pas' {Form1};{$R *.res}begin
Application.Initialize;
Application.Title := '光盘垃圾文件检测';
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
procedure delay(msec:integer); 过程没有用到