while 该目下还有文件 do
begin
打开这个文件,
查找“美国”,
找到,替换称“中国”
关闭该文件
搜索下一文件。
end.
来自:cAkk 时间:1999-9-24 1:15:22 ID:137052
一个函数,结果用参数foundresult返回:
function SearchFile(mainpath:string;filename:string; var foundresult:TStrings):Boolean;
var
i:integer;
Found:Boolean;
subdir1:TStrings;
searchRec:TsearchRec;
begin
if right(mainpath,1)<>'/' then mainpath:=mainpath+'/';
found:=false;
if Trim(filename)<>'' then
begin
subdir1:=TStringList.Create;
if (FindFirst(mainpath+'*.*', faDirectory,SearchRec)=0) then
begin
if IsValidDir(SearchRec) then subdir1.Add(SearchRec.Name);
while (FindNext(SearchRec) = 0) do
begin
if IsValidDir(SearchRec) then subdir1.Add(SearchRec.Name);
end;
end;
FindClose(SearchRec);
//查找当前目录。
if (FindFirst(mainpath+'*.*', faAnyFile-faDirectory, SearchRec)=0) then
begin
foundresult.Add(mainpath+SearchRec.Name);
while (FindNext(SearchRec) = 0) do
begin
foundresult.Add(mainpath+SearchRec.Name);
end;
end;
FindClose(SearchRec);
for i:=0 to subdir1.Count-1 do
found:=Searchfile(mainpath+subdir1.Strings+
'/',Filename,foundresult)or found;
subdir1.Free;
end;
result:=found;
end;