L
lizheng
Unregistered / Unconfirmed
GUEST, unregistred user!
我想让程序循环查找E盘上的文件,并将其写入一个文件中。
procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
f:textfile;
begin
FindFirst('e:/unit/*.*', faAnyFile, SearchRec);
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
while FindNext(SearchRec) = 0 do
begin
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
s:=string(Searchrec.Name);
append(F);
writeln(F,s);
end;
FindClose(SearchRec);
PostQuitMessage(0);
end;
FindClose(SearchRec);
end;
上述循环达不到我想要的目的,但是如果按下面的执行便能达到目的。
var
s,path:string
f:textfile;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindFirst(path, faAnyFile, SearchRec);
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if FindNext(SearchRec) = 0 then
begin
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
s:=string(Searchrec.Name);
append(F);
writeln(F,s);
end
else
FindClose(SearchRec);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
path:='e:/unit/*.*';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
AssignFile(F, OpenDialog1.FileName);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
f:textfile;
begin
FindFirst('e:/unit/*.*', faAnyFile, SearchRec);
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
while FindNext(SearchRec) = 0 do
begin
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
s:=string(Searchrec.Name);
append(F);
writeln(F,s);
end;
FindClose(SearchRec);
PostQuitMessage(0);
end;
FindClose(SearchRec);
end;
上述循环达不到我想要的目的,但是如果按下面的执行便能达到目的。
var
s,path:string
f:textfile;
procedure TForm1.Button1Click(Sender: TObject);
begin
FindFirst(path, faAnyFile, SearchRec);
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if FindNext(SearchRec) = 0 then
begin
Label1.Caption := SearchRec.Name + ' is ' + IntToStr(SearchRec.Size) + ' bytes in size';
s:=string(Searchrec.Name);
append(F);
writeln(F,s);
end
else
FindClose(SearchRec);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
path:='e:/unit/*.*';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
AssignFile(F, OpenDialog1.FileName);
end;
end;