贴一下代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Controls, Forms,
Dialogs, StdCtrls, FileCtrl, Classes, Grids, Outline, DirOutln;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
Button2: TButton;
DirectoryOutline1: TDirectoryOutline;
DriveComboBox1: TDriveComboBox;
Label1: TLabel;
Memo3: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure DriveComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
number:integer;
implementation
{$R *.dfm}
function newline(tt:string):string;
var i,j,lines:integer;
ss:string;
begin
for lines:=Form1.memo2.lines.count-1 downto 0 do
begin
if (pos(tt,Form1.memo2.lines[lines])<>0) then
begin
i:=pos('DHTMLSound(',Form1.memo2.lines[lines+1]);
j:=pos(')">',Form1.memo2.lines[lines+1]);
ss:=copy(Form1.memo2.lines[lines+1],i+11,j-i-11);
break;
end;
end;
result:='onmouseover="DHTMLSound('+ss+')" />';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:byte;
F: TextFile;
path,singleLine,content,tt,tt1,tt2: string;
lines:integer;
begin
for lines:=0 to memo3.lines.count-1 do
begin
path:=memo3.lines[lines];
memo2.Lines.LoadFromFile(path);
content:=memo2.Text;
AssignFile(F, path);
Reset(F);
while (not eof(F)) do
begin
Readln(F, singleLine);
i:=pos('" href="#',singleLine);
if i<>0 then
begin
j:=pos('" alt="',singleLine);
tt:=copy(singleLine,i+9,j-i-9);
tt1:=copy(singleLine,1,i+1);
tt2:= tt1+newline(tt) ;
Memo1.Lines.Append(tt2);
end
else
Memo1.Lines.Append(singleLine);
end;
CloseFile(F);
memo1.Lines.SaveToFile(path);
memo1.Clear;
memo2.Clear;
end;
Label1.Caption:=Label1.Caption+' 处理完: '+inttostr(memo3.lines.count)+' 个';
end;
function searchHtm(dir:string):boolean;
var sr:tsearchrec;
sdir:string;
begin
sdir:=dir+'*.*';
if findfirst(sdir,faanyfile,sr)=0 then
begin
repeat
begin
if (sr.Name ='.') or (sr.Name ='..') then continue;
if sr.Attr and fadirectory=0 then
begin
if ExtractFileExt(sr.Name)='.htm' then
begin
form1.Memo3.Lines.Append(dir+sr.Name);
number:=number+1;
end;
end else
begin
searchHtm(dir+sr.Name+'\');
end;
end
until findnext(sr)<>0;
findclose(sr);
end;
result:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
var dir:string;
begin
number:=0;
Label1.Caption:='网页文件: 个';
dir :=DirectoryOutline1.Directory+'\';
if searchHtm(dir) then Label1.Caption:='网页文件: '+inttostr(number)+' 个';
number:=0;
end;
procedure TForm1.DriveComboBox1Change(Sender: TObject);
var str:string;
cc:char;
begin
str:=DriveComboBox1.Text;
cc:=str[1];
DirectoryOutline1.Drive:=cc;
end;
end.