你需要用到两个函数,第一个:批量搜索指定目录下的所有asp文件 procedure TForm1.FindFiles(Apath:string); var FSearchRec,DSearchRec:TSearchRec; FindResult:integer; begin if apath[length(apath)]<>'\' then apath:=apath+'\'; FindResult:=FindFirst(Apath+'*.asp',faAnyFile+faHidden+faSysFile+faReadOnly,FSearchRec); try while FindResult=0 do begin ListBox1.Items.Add(Apath+FSearchRec.Name); FindResult:=FindNext(FSearchRec); end; FindResult:=FindFirst(Apath+'*.*',faDirectory,DSearchRec ); while FindResult =0 do begin if ((DSearchRec.Attr and fadirectory)=fadirectory) and (leftstr(DSearchRec.Name,1)<>'.') then FindFiles(Apath+DSearchRec.Name); FindResult:=FindNext(DSearchRec ); end; finally FindClose(FSearchRec); end; end; 第二个,替换文件里的内容 uses strutils;st:tstringlist; st:=tstringlist.create; st.loadfromfile('A\x\k\a.asp'); st.text:=ansireplacetext(st.text,'文字,'我的东东'); st.free;另外,技术贴子最好不要发在非技术区。不过对我来说赚点水分也是好的,呵呵
用Tstringlist读取后,replace好了。。
procedure TForm1.FindFiles(Apath:string);
var
FSearchRec,DSearchRec:TSearchRec;
FindResult:integer;
begin
if apath[length(apath)]<>'\' then apath:=apath+'\';
FindResult:=FindFirst(Apath+'*.asp',faAnyFile+faHidden+faSysFile+faReadOnly,FSearchRec);
try
while FindResult=0 do
begin
ListBox1.Items.Add(Apath+FSearchRec.Name);
FindResult:=FindNext(FSearchRec);
end;
FindResult:=FindFirst(Apath+'*.*',faDirectory,DSearchRec );
while FindResult =0 do
begin
if ((DSearchRec.Attr and fadirectory)=fadirectory) and (leftstr(DSearchRec.Name,1)<>'.') then
FindFiles(Apath+DSearchRec.Name);
FindResult:=FindNext(DSearchRec );
end;
finally
FindClose(FSearchRec);
end;
end;
第二个,替换文件里的内容
uses strutils;st:tstringlist;
st:=tstringlist.create;
st.loadfromfile('A\x\k\a.asp');
st.text:=ansireplacetext(st.text,'文字,'我的东东');
st.free;另外,技术贴子最好不要发在非技术区。不过对我来说赚点水分也是好的,呵呵